Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select an item by attribute without jquery?

I need select element like this: $('[data-key=' + objectId + ']'), but i need select this without jquery, using document.querySelector or something else on pure JS.

like image 359
pgrekovich Avatar asked Sep 19 '25 20:09

pgrekovich


1 Answers

You can do it with document.querySelectorAll('[data-key=' + objectId + ']') and loop through all results

var allKeys = document.querySelectorAll('[data-key=' + objectId + ']');

[].forEach.call(allKeys, function(elem){
   console.log(elem); //Do your stuff with each element
});
like image 95
Vicky Gonsalves Avatar answered Sep 21 '25 08:09

Vicky Gonsalves