jQuery zapravo nema .hasAttr()
funkciju. Mogli biste pretpostaviti da jest, ali nažalost, nije.
StackOverflow nit ima nekoliko prilično dobrih rješenja.
Nabavite atribut, provjerite vrijednost
var attr = $(this).attr('name'); // For some browsers, `attr` is undefined; for others, `attr` is false. Check for both. if (typeof attr !== typeof undefined && attr !== false) ( // Element has this attribute )
Izvorni JavaScript ima način
Ako imate samo jQuery referencu ...
$(this)(0).hasAttribute("name"); jQObject(0).hasAttribute("name");
Filtrirajte odabir
$(this).is('(name)'); $(this).filter("(name='choice')");