Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Attribute('id') Exists in jQuery

How can I check if an attribute Id exists in jQuery?

I searched around and found that this should work:

if ($(this).attr('id').attr('id'))
{

}

I still get this error: TypeError: Object gauge1 has no method 'attr'

like image 882
CodeMan5000 Avatar asked Sep 27 '12 16:09

CodeMan5000


2 Answers

This itself will work:

if($(this).attr("id"))

Check existing jsfiddle on the issue: http://jsfiddle.net/rwaldron/wVqvr/4/

like image 160
Adriano Carneiro Avatar answered Sep 28 '22 06:09

Adriano Carneiro


Just try it the old way

if (this.id) { 
    //do something
}
like image 20
Selvakumar Arumugam Avatar answered Sep 28 '22 05:09

Selvakumar Arumugam