In trying to select elements that have any attributes, the following throws a jQuery syntax error.
$("div[*]")
Is there a selector to check if a tag has any attributes?
Tested with jQuery 1.3
hasAttribute() The Element. hasAttribute() method returns a Boolean value indicating whether the specified element has the specified attribute or not.
jQuery [attribute|=value] Selector The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us"). Tip: This selector is often used to handle language attributes.
I don't think so but this should do the trick
$('*').filter(function(){return this.attributes.length;})
and the opposite:
$('*').filter(function(){return !this.attributes.length;})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With