1

hide()jqueryの機能を使用して、ページの読み込み時に特定のクラスのすべての要素を非表示にしています。リンクがクリックされたときに、ID に基づいて要素を再度表示しようとしています。

クラスが非表示の 7 つの要素があり、それぞれに異なる ID があります。含まれているリンクをhref="#element-id"クリックすると、その要素のみが表示され、他のすべての要素は非表示になります。

要素を隠している私の現在のコードは次のとおりです。

var menu = $('div.menu-wrapper');
menu.hide();

そして、これがクリック時に正しい要素を表示するはずの私が持っているものです:

$('area').click(function() {
    if($(this).attr('id') !== 'button') {
        var target = $(this).attr('href');
        target.toggle('slide', {
            direction: 'right'
        }, 900);    
    }
});

現在、要素をクリックしても何も起こりません。クラスと正しい ID をmenu-wrapper持つ要素のみを表示しながら、クラスを持つすべての要素を非表示にするにはどうすればよいですか?menu-wrapper

4

1 に答える 1

1

試す

var menu = $('div.menu-wrapper');
menu.hide();
//register the event handler to area elements other than #button
$('a:not(#button)').click(function () {
    //hide all elements referred menu
    menu.hide();
    //get the target jQuery wrapper, the href need to start with #
    var target = $($(this).attr('href'));
    target.toggle('slide', {
        direction: 'right'
    }, 900);
});
于 2013-09-30T15:22:19.260 に答える