DragEvent.dataTransfer — drag data
DragEvent.dataTransfer exposes the DataTransfer object for a drag event. Access to its payload depends on the operation's phase; a script-created event can return null.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
DragEvent.dataTransfer exposes the DataTransfer object for a drag event. Access to its payload depends on the operation's phase; a script-created event can return null.
Element represents a DOM element, not an arbitrary node. It provides navigation, attributes, and content replacement; browsers also expose layout measurements and scrolling. Distinguish tree structure, client-area dimensions, and viewport-relative rectangles.
Element.after inserts nodes and text as siblings, normally immediately after the element. It does not add children to that element.
Create animations with Element.animate by defining keyframes and timing options, then control the returned Animation object.
`Element.append` adds nodes and text at the end of an element and returns `undefined`. If `a` and `b` are distinct elements, a successful call to `element.append(a, b, a)` leaves `b` followed by `a` at the end: the last occurrence of `a` moves the node rather than copying it. If instead `a` is a `DocumentFragment` containing one text node and `b` is a separate element, the first occurrence of `a` places the text node before `b` and empties the fragment. The last occurrence adds nothing, and the fragment itself is never inserted.
Element.attachShadow() attaches a Shadow DOM root to a supported element and returns a ShadowRoot. The required open or closed mode controls access through host.shadowRoot, not a security boundary.
Element.before() inserts nodes and text into the element’s parent, not into the element itself. They normally go before the reference element.
Element.classList provides a live DOMTokenList for reading and changing individual classes without replacing the entire class attribute.
On an HTML element, use `className` to read or replace the `class` attribute value as a string, not an array of classes. `SVGElement.className` is read-only and returns an `SVGAnimatedString`.
Element.closest(selectors) checks the element and then its ancestors. It returns the first element matching the CSS selector, or null.
Element.getAttribute reads a DOM element's attribute as a string, or returns null when that attribute does not exist.
Element.getBoundingClientRect() returns a DOMRect describing an element’s viewport-relative position and size. The measurement includes padding, borders, and CSS transforms; the result is a snapshot.
Element.id reads and changes a DOM element’s id attribute. A missing attribute produces an empty string.
Element.innerHTML reads an element’s contents as HTML markup or replaces them with nodes parsed from supplied markup. It does not sanitize untrusted data and can introduce XSS.
Element.lastElementChild returns the last direct child that is an element, or null. It skips text and comments.
Element.matches tests whether a particular element matches a CSS selector. It returns a boolean, not an element; invalid selector syntax causes an exception.
Element.nextElementSibling returns the nearest following element with the same parent, or null. It skips text nodes and comments.
Element.prepend inserts nodes and text before an element’s first child. If a and b are distinct elements, prepend(a, b, a) inserts b followed by a, without duplicating a.
The previousElementSibling property returns the nearest earlier element with the same parent, or null, skipping text and comments.
Element.querySelector finds the first descendant matching a CSS selector. It returns an element or null; an invalid selector causes an exception.
Element.querySelectorAll returns a static NodeList of descendants matching a CSS selector. Later tree changes do not update the list.
releasePointerCapture(pointerId) releases an element's capture of a particular pointer, restoring normal position-based event targeting.
The element.remove() method detaches an element from its parent. It takes no arguments, returns undefined, and does nothing when the element has no parent.
Element.removeAttribute removes an element's attribute by name. It returns undefined; a missing attribute does not cause an error.