FindByAttributeValue("Attribute-Name", "Attribute-Value");
P.S. se si sa esattamente elemento-tipo, si aggiungono 3 ° parametro (cioè div, a, p ...etc...
):
FindByAttributeValue("Attribute-Name", "Attribute-Value", "div");
ma in un primo momento, definire questa funzione:
function FindByAttributeValue(attribute, value, element_type) {
element_type = element_type || "*";
var All = document.getElementsByTagName(element_type);
for (var i = 0; i < All.length; i++) {
if (All[i].getAttribute(attribute) == value) { return All[i]; }
}
}
P.S. aggiornato per raccomandazioni commenti.
fonte
2014-01-24 10:15:02
Duplicare se siete alla ricerca di un Jquery Sol: http://stackoverflow.com/questions/696968/jquery-v1-3-2-find-element- by-attribute – Rajat
Puoi aggiornare la risposta accettata alla soluzione moderna, la risposta di Wojtek? –