In javaScript, how is the best way to get a specific html node where I know the attribute name and attribute value, and many html nodes can have the same attribute name? The attribute name is a data attribute.
Here is some example html:
<div class="misc1" data-test="value1" data-test="value2"></div>
<div class="misc2" data-test="value3" data-test="value4"></div>
If I want to get the html node with data-test="value3", do I need to do something along the lines of:
var elements = document.querySelectorAll("[data-test]");
for (i = 0; i < elements.length; i++) {
for(x = 0; x < elements[i].attributes.length; x++) {
//Do an attribute value check??
}
}
Can I please have some help with the code and I would not like to use jQuery?