Can you please tell me if there is any DOM API which search for an element with given attribute name and attribute value:
Something like:
doc.findElementByAttribute("myAttribute", "aValue");
Modern browsers support native querySelectorAll so you can do:
querySelectorAll
document.querySelectorAll('[data-foo="value"]');
https://developer.mozilla.org/en-US/docs/Web/API/Document.querySelectorAll
Details about browser compatibility:
You can use jQuery to support obsolete browsers (IE9 and older):
$('[data-foo="value"]');
2.1m questions
2.1m answers
60 comments
57.0k users