30 December 2022

The Vanilla JavaScript equivalent of jQuery's .find() method is the .querySelectorAll() method. The function allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements. So you won't get jQuery elemens as result of the JavaScript alternative, but you will get DOM elements instead.

Source code viewer
  1. // Returns the first element that is matching the specified group of selectors.
  2. var container = window.document.querySelector("#id");
  4. // Returns a list (NodeList) of elements matching the specified group of selectors.
  5. var matches = window.document.querySelectorAll(".container .class");
  6. // Use forEach to iterate the corresponding elements.
  7. matches.forEach(function(element) {
  8. // ...
  9. });
Programming Language: Javascript