JavaScript: DOM & Event Handling
59 cards · 🇺🇸 English
DOM traversal, manipulation, and event handling in the browser.
Study all 59 cards for free
Flashcards, quizzes, pixel-art games and a daily review that remembers for you.
Try the first 10 cards
1 / 10DOM
Tap the card for the answer · swipe right if you knew it, left if not
Already have an account? Sign in
Cards
- 1DOMDocument Object Model - a programming interface representing the HTML/XML document as a tree structure of nodes and objects that can be manipulated with JavaScript.
- 2the DOM vs JavaScriptJavaScript is the programming language; DOM is a Web API that JavaScript uses to access and manipulate web documents. DOM is not part of JavaScript itself.
- 3Document.querySelector()Returns the first element matching a CSS selector. Example: document.querySelector('.class') returns the first element with that class.
- 4Document.querySelectorAll()Returns a NodeList of all elements matching a CSS selector. Example: document.querySelectorAll('p') returns all paragraph elements.
- 5querySelector vs getElementByIdgetElementById is faster but only selects by ID. querySelector is more flexible (accepts any CSS selector) but slightly slower.
- 6Document.createElement()Creates a new HTML element node. Example: const div = document.createElement('div') creates a new div element in memory (not yet added to page).
- 7Element.appendChild()Adds a node as the last child of a parent element. Example: parent.appendChild(child) inserts child at the end.
- 8Element.removeChild()Removes a child node from its parent. Example: parent.removeChild(child) removes child from parent.
- 9Element.remove()Modern method to remove an element directly without referencing the parent. Example: element.remove() removes the element.
- 10InnerHTMLGets or sets the HTML content inside an element. Example: div.innerHTML = '<p>Hello</p>' replaces content with new HTML.
- 11TextContentGets or sets the text content of an element (strips HTML tags). Example: div.textContent = 'Hello' sets plain text.
- 12Element.getAttribute()Gets the value of an attribute. Example: img.getAttribute('src') returns the image source.
- 13Element.setAttribute()Sets an attribute value. Example: img.setAttribute('src', 'image.png') changes the image source.
- 14Element.classListA DOMTokenList of class names with methods: add(), remove(), toggle(), contains(). Example: div.classList.add('active').
- 15Element.styleAccesses inline CSS styles. Example: div.style.color = 'red' sets inline style. Use camelCase for multi-word properties (backgroundColor).
- 16element.style vs getComputedStyle()element.style only accesses inline styles. getComputedStyle() returns all computed styles including CSS from stylesheets.
- 17AddEventListener()Attaches an event handler to an element. Example: button.addEventListener('click', handler). Multiple handlers can be attached.
- 18RemoveEventListener()Removes an event handler. Requires the same function reference: button.removeEventListener('click', handler).
- 19Common DOM eventsclick, dblclick, mouseenter, mouseleave, keydown, keyup, submit, change, focus, blur, load, scroll.
- 20Event.preventDefault()Prevents the default browser action. Example: form.addEventListener('submit', e => e.preventDefault()) stops form submission.
- 21Event.stopPropagation()Stops event from bubbling up to parent elements. Prevents parent handlers from being triggered.
- 22Event bubblingEvents propagate from the target element up through ancestors to the document root. Parent handlers are triggered after child handlers.
- 23Event capturingEvents propagate from document root down to the target element. Opposite of bubbling. Enable with addEventListener('click', handler, true).
- 24Event.targetThe element that triggered the event (where the event originated). May be a child of the element with the listener.
- 25Event.currentTargetThe element that has the event listener attached. Always the element where addEventListener was called.
- 26Event delegationAttaching a single event listener to a parent to handle events from multiple children. Uses event.target to identify which child triggered the event.
- 27Why use event delegation?More efficient than attaching listeners to many elements. Works with dynamically added elements. Reduces memory usage.
- 28Document.getElementById()Selects an element by its ID attribute. Example: document.getElementById('header'). Returns null if not found.
- 29Document.getElementsByClassName()Returns a live HTMLCollection of elements with the specified class. Example: document.getElementsByClassName('item').
- 30Document.getElementsByTagName()Returns a live HTMLCollection of elements by tag name. Example: document.getElementsByTagName('p') returns all paragraphs.
And 29 more cards. Study the whole deck free
Articles about this deck
More Programming decks
See all- 🌐
APIs: REST, GraphQL & HTTP Status Codes
108 cards · 🇺🇸 English
REST and GraphQL API concepts plus common HTTP status codes.
- 🎨
CSS: Box-Modell, Selektoren & Media Queries
129 cards · 🇺🇸 English
Das CSS-Box-Modell, Selektortypen, Media Queries und Animationen.
- 📄
HTML : balises et attributs
99 cards · 🇺🇸 English
Éléments HTML essentiels et leurs attributs.
- 🎨
CSS: Box Model, Selectors & Media Queries
129 cards · 🇺🇸 English
The CSS box model, selector types, media queries, and animations.
- 🔒
Web Security: OWASP & Authentication
35 cards · 🇺🇸 English
Common web vulnerabilities (OWASP Top 10) and authentication concepts.
- 🎨
CSS : Flexbox et Grid
58 cards · 🇺🇸 English
Mise en page avec CSS Flexbox et Grid.
