Measuring an element’s bounding rectangle height
`getBoundingClientRect()` measures an element’s geometry relative to the viewport. Read `DOMRect.height` to get the rectangle’s height in CSS pixels.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`getBoundingClientRect()` measures an element’s geometry relative to the viewport. Read `DOMRect.height` to get the rectangle’s height in CSS pixels.
Measure an element’s position and size relative to the viewport, and distinguish those measurements from the left and top offsets of its client area.
Check whether an element has a named attribute and use the result to decide whether to scroll to it. Distinguish attribute presence from its value, and scrolling from setting focus.
Choose between parsing markup and inserting literal text. Learn how to prevent DOM XSS and what changes when Trusted Types are enforced.
Use `innerHTML` to read or replace an element’s contents, and `className` to read or set its CSS classes.
Read and replace an element’s markup, and distinguish elements by local name and namespace when HTML and SVG share the same DOM tree.
Use `querySelectorAll()` to find matching descendants, `hasAttribute()` to check whether an attribute is present, and `getClientRects()` to read layout geometry. None of these results alone tells you whether the user can see an element.
Find the first descendant that matches a CSS selector, handle a missing match, and read or replace the markup inside the selected element.
Find descendants of an element using CSS selectors. Choose between the first match and a static list of all matches.
Replace or clear all of an element’s child nodes, and read or set its entire `class` attribute without changing its children.
Use `replaceChildren()` to replace or clear an element’s child nodes, and `hasAttribute()` to check whether the element itself has an attribute, regardless of its value.
Read and set an element’s scroll position, distinguish the full scrollable height from the visible inner height, and replace child nodes without parsing strings as HTML.
`message` is the event’s diagnostic text, while `error` is the associated JavaScript value. That value need not be an `Error` object.
In browsers, `queueMicrotask()` and Promise reactions share a microtask queue. `setTimeout()` schedules a separate task, even with a delay of `0`.
Use `{ once: true }` to make an event listener run at most once per registration. The registration is removed before its callback runs.
`passive: true` lets a listener receive the event without being able to cancel its default action. Leaving the option out is not always equivalent to passing `false`.
Tell the event’s target apart from the object running the listener, and see how the `capture` option changes listener order in the DOM.
`event.target` identifies the event’s target, while `event.type` gives its name. `event.currentTarget` identifies the object on which the running listener was registered.
`event.type` tells you what kind of event it is; `event.timeStamp` tells you when it was created, in milliseconds relative to a time origin.
A `function` declaration can be called before it appears in source code. A function expression used as an initializer does not make its function available the same way.
`fn.length` describes a function's expected arity, while `arguments.length` counts the arguments supplied in a particular call.
Distinguish a function's own prototype chain from the `.prototype` property used to create instances, and see how `new`, `constructor`, and `super()` fit into inheritance.
Distinguish a function’s own prototype chain from the prototype of its instances, and share one method across those instances.
In an unmodified environment, reading `Function.prototype.prototype` gives `undefined`. That does not mean `Function.prototype` has no internal prototype.