Checking whether a class name exists?
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(开发者_Go百科'.temp').length
-> this is not working
jQuery.fn.exists = function(){
return jQuery(this).length>0;
}
if ($(selector).exists()) {
// Do something
}
$('.temp').length
does work.
See http://jsfiddle.net/ThiefMaster/wEXVu/
精彩评论