hadakasir
hadakasir

Reputation: 13

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() {
  ...
});

Upvotes: 1

Views: 94

Answers (1)

Pointy
Pointy

Reputation: 414036

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.

Upvotes: 1

Related Questions