— javascript, web-development — 1 min read
From Javascript, both the methods can be used to return multiple elements in the document but the difference is in what it returns.
1var elements1 = document.querySelectorAll(".clickable"); 2var elements2 = document.getElementsByClassName("clickable");
getElementsByClassName()
is useful when working with dynamic elements as its updated when the DOM changes.