Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a jQuery selector to check if a tag has any attributes?

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

like image 980
Doug Domeny Avatar asked Mar 15 '10 15:03

Doug Domeny


People also ask

How do you know if an element has an attribute?

hasAttribute() The Element. hasAttribute() method returns a Boolean value indicating whether the specified element has the specified attribute or not.

What is attribute selector jQuery?

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.


1 Answers

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;})
like image 192
Ariel Popovsky Avatar answered Oct 05 '22 22:10

Ariel Popovsky