How to get element by attribute "data-tid" with value of "43574" in Javascript? There is only one element with this value.
Please avoid using jQuery.
How to get element by attribute "data-tid" with value of "43574" in Javascript? There is only one element with this value.
Please avoid using jQuery.
In recent browsers you can use
var elem = document.querySelector('[data-tid="43574"]')
but be warned it's not a fast selector.
To use a variable, do
var elem = document.querySelector('[data-tid="'+myValue+'"]')
or use
var elems = document.querySelectorAll('[data-tid]')
and loop over the found elements to check the value.
querySelector since it's only one element?querySelector instead of querySelectorAll, since it can stop once it finds the element.'[data-tid="'+VARIABLE+'"]'