Skip to content Skip to sidebar Skip to footer

Js Selector Combined With Jquery

I wonder if there's a way to combine a JS selector with jQuery functions methods like that: document.getElementsByClassName('example').on('click', function() { ... });

Solution 1:

You can pass your node list to the jQuery constructor:

$(document.getElementsByClassName("example")).on("click", function() {
  // ...
});

I don't know for sure how long jQuery has recognized when node lists are passed to the constructor, but it seems to work now.

Post a Comment for "Js Selector Combined With Jquery"