Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery check if element contains any attribute

I can check if an element have a specific attribute with:

if ($('#A').attr('myattr') !== undefined) {
    // attribute exists
} else {
    // attribute does not exist
}

How can I check if an element have any attribute?

Thank you

like image 296
Mircea Avatar asked Feb 10 '10 20:02

Mircea


1 Answers

If you want to see if the element has a particular attribute, just do this:

if ($('#something').is('[attribute]')) {
  // ...
}
like image 180
Pointy Avatar answered Oct 06 '22 05:10

Pointy