kiran
kiran

Reputation: 301

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('.temp').length -> this is not working

Upvotes: 0

Views: 672

Answers (2)

Steve Kelly
Steve Kelly

Reputation: 373

jQuery.fn.exists = function(){
    return jQuery(this).length>0;
}

if ($(selector).exists()) {
    // Do something 
}

Upvotes: 2

ThiefMaster
ThiefMaster

Reputation: 318808

$('.temp').length does work.

See http://jsfiddle.net/ThiefMaster/wEXVu/

Upvotes: 0

Related Questions