Reputation: 301
I want to check whether a class name exist irrespective of its id or tag.
Suppose I'm having class name "temp".
I need to check something like jQuery('.temp').length
-> this is not working
Upvotes: 0
Views: 672
Reputation: 373
jQuery.fn.exists = function(){
return jQuery(this).length>0;
}
if ($(selector).exists()) {
// Do something
}
Upvotes: 2
Reputation: 318808
$('.temp').length
does work.
See http://jsfiddle.net/ThiefMaster/wEXVu/
Upvotes: 0