10

クリックされたli要素に写真のクラスがない場合にコードを実行するifステートメントを作成しようとしています。

$('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');
    }
});
4

3 に答える 3

9

jQueryのを使用するだけ.isです:

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

または、必要に応じて、次のようにします.hasClass

if(!$(this).hasClass('some-class')) { // ...
于 2012-07-01T01:04:03.537 に答える
8

:notセレクターを使用します。

$("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");
});
于 2012-07-01T01:03:59.423 に答える
3
if(!$(this).hasClass('className')) {
    // clicked element does not have the class
}
于 2012-07-01T01:04:57.030 に答える