tags:

views:

36

answers:

1

Hi All,

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

A: 

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();
elusive
I have tried but wrapping this makes no difference...I need to select all div.rtmenu prev to `this`
Nasir
Can you show me some HTML? This would make this a lot easier.
elusive
I'm pretty sure that isn't the issue, `.not(this)` works well.
Kobi
I second with [Kobi](http://stackoverflow.com/users/7586/kobi)
Reigel
I just need some way to exclude div.rtmenu previous to `this`
Nasir
How is the hierarchy structured? Are all relevant elements children of a single element, or are they nested somehow? If they are not nested, you could simply use `$(this).prevAll('.rtmenu:visible')` to select them.
elusive