开发者

Checking whether a class name exists?

开发者 https://www.devze.com 2023-02-26 04:28 出处:网络
I want to check whether a class name exist irrespective of its id or tag. Suppose I\'m having class name \"temp\".

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号