2012-07-01 22 views
7

नहीं है, तो मैं एक कथन बनाने की कोशिश कर रहा हूं जो कोड चलाता है यदि क्लिक किए गए ली तत्व में फ़ोटो की कक्षा नहीं है।जांचें कि क्लिक किए गए तत्व में कोई विशिष्ट वर्ग

$('div.menu li').click(function(){ 
    var content = $(this).attr('class'); 
    if (/* I can't figure out the correct syntax that goes here? */){ 
     $("div.content_wrapper, div.content").hide(); 
     $('div.content_wrapper').animate({width: 'toggle'}); 
     $('div.content_wrapper, div.' + content).show(); 
     $('div.menu li').removeClass('menuactive'); 
     $(this).addClass('menuactive'); 
    } 
}); 

उत्तर

8

उपयोग :not selector:

$("div.menu li:not(.photo)").click(function(){ 
    $("div.content_wrapper, div.content").hide(); 
    $("div.content_wrapper").animate({width: "toggle"}); 
    $("div.content_wrapper, div." + content).show(); 
    $("div.menu li").removeClass("menuactive"); 
    $(this).addClass("menuactive"); 
}); 
+0

+1 स्मार्ट उत्तर। – undefined

+0

दिलचस्प, धन्यवाद! – farrkling

6

बस का उपयोग jQuery के .is:

if(!$(this).is('.some-class')) { // ... 

या, यदि आप इतना पसंद करते हैं, .hasClass:

if(!$(this).hasClass('some-class')) { // ... 
+0

बढ़िया! धन्यवाद! – farrkling

+2

इसके बजाय @ EH_warch के उत्तर का उपयोग करें, मैंने बाहरी चयनकर्ता पर ध्यान नहीं दिया :) – Ryan

1
if(!$(this).hasClass('className')) { 
    // clicked element does not have the class 
} 
संबंधित मुद्दे