开发者

How do I write .not(this) to include all previous DIVs to this, using JQuery?

开发者 https://www.devze.com 2023-01-15 16:25 出处:网络
I have开发者_运维问答 a tree structure menu. What I am trying to achieve is to add the \'.toggle-me\' class to the next submenu that shows up.

I have开发者_运维问答 a tree structure menu. What I am trying to achieve is to add the '.toggle-me' class to the next submenu that shows up.

I have achieved this to some degree, although I need to some get the .not(this) to include all .rtmenu's before this?

Here is the code I'm working with:

$('.rtmenu').live('click', function(){ 
    $('.rtmenu:visible').not(this).addClass('toggle-me'); 
    $('.toggle-me').toggle()
});

Please let me know if you need clarification. Much Appreciated, Thanks


I think you should try wrapping this with jQuery, since this is not a jQuery object:

$('.rtmenu:visible').not($(this)).addClass('toggle-me');

Additionally, i would omit the toggle-me class. You could simply write:

$('.rtmenu:visible').not($(this)).toggle();
0

精彩评论

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