Querying the DOM is an essential skill every web developer should have. Learn how to query the DOM quickly and efficiently with this collection of JavaScript tips and tricks.
Returns an array containing all the siblings of the given element.
JavaScript, Browser · Oct 19, 2020
Returns all the ancestors of an element from the document root to the given element.
JavaScript, Browser · Jan 5, 2021
Finds all the ancestors of an element up until the element matched by the specified selector.
JavaScript, Browser · Jan 6, 2021
Finds the closest matching node starting at the given node
.
JavaScript, Browser · Apr 22, 2021
Checks if the parent
element contains the child
element.
JavaScript, Browser · Nov 3, 2020
Finds the anchor node closest to the given node
, if any.
JavaScript, Browser · Apr 22, 2021
Fetches all images from within an element and puts them into an array.
JavaScript, Browser · Oct 22, 2020
Ever wanted to create your own jquery-like query selector shorthand? Here's how!
JavaScript, Browser · Jun 12, 2021
Checks if the element specified is visible in the viewport.
JavaScript, Browser · Oct 22, 2020
Here's a quick and easy way to select the currently focused DOM element in JavaScript.
JavaScript, Browser · Oct 23, 2022
Returns an array of HTML elements whose width is larger than that of the viewport's.
JavaScript, Browser · Oct 22, 2020
Using Document.elementFromPoint()
to easily get the element at a specific point on the page.
JavaScript, Browser · Dec 18, 2022
Finds the distance from a given element to the top of the document.
JavaScript, Browser · Jan 5, 2021
Increase your JavaScript code's performance when working with the DOM by leveraging this simple trick.
JavaScript, Browser · Jun 12, 2021