Loop through DOM elements and make changes
The querySelectorAll()
returns a DOM list that includes elements that matches the query. The equivalent to $().each()
in JavaScript is document.querySelectorAll().forEach()
function.
Refer to the following code snippet to learn how to loop through DOM elements and make changes through jQuery and vanilla JavaScript:
// Select multiple elements and hide them using jQuery
$(".blog-post").hide();
// Select multiple elements and hide them using vanilla JavaScript
document.querySelectorAll(".blog-post").forEach((post) => {
post.style.display = "none";
});