Jquery: toggling the siblings?

Instead of a toggle() function which is ending up in the wrong state you ca just use a normal click function and use toggleClass() instead, like this: $(this). Click(function (){ var myUL = $(this). Siblings(".

Selected"). ToggleClass("showme"); $("ul"). Not(myUL).

RemoveClass("showme"); }) You can give it a try here this does a toggleClass() on the sibling, then looks for all other ul elements, by filtering out the sibling with not() This cleans up a bit making it easier, the main issue it resolves is the non-exclusion of the sibling from removeClass() this is what caused your toggle() state to be incorrect before.

Instead of a .toggle() function which is ending up in the wrong state you ca just use a normal click function and use .toggleClass() instead, like this: $(this). Click(function (){ var myUL = $(this). Siblings(".

Selected"). ToggleClass("showme"); $("ul"). Not(myUL).

RemoveClass("showme"); }); You can give it a try here, this does a .toggleClass() on the sibling, then looks for all other elements, by filtering out the sibling with .not(). This cleans up a bit making it easier, the main issue it resolves is the non-exclusion of the sibling from .removeClass(), this is what caused your .toggle() state to be incorrect before.

Thanks you so much! I had completely forgotten about .toggleClass()! It works perfectly now :-))) – lauthiamkok Aug 6 '10 at 16:33 @lauthiamkok - Welcome :) – Nick Craver?

Aug 6 '10 at 16:35 sorry I have to come back to you for the same problem... I just realised that the current parent does not toggle anymore, it only toggle when I click on other parents... have a look here, lauthiamkok. Net/tmp/jquery/toggle/index_1. Html for instance, when I click on the link 2 only, I was hoping to show its sibling too.

And hide it when I click on this parent again. Is it possible...? thanks! – lauthiamkok Aug 6 '10 at 17:26.

See the modified function. Just one change and it will work fine. $("a").

Each(function () { if ( $(this).siblings().size() > 0) { $(this). Append("has child"); $(this). Toggle( function (){ // $("ul").

RemoveClass("showme"); Change this $(this). Next("ul"). RemoveClass("showme"); $(this).

Siblings(". Selected"). AddClass("showme"); return false; //$(this).next().

Css({display: "block"}); }, function (){ $(this). Siblings(". Selected").

RemoveClass("showme"); return false; //$(this).next(). Css({display: "none"}); }); } }).

Still having the problem with this suggestion... but I have changed the code to as Nick suggested above, $(this). Click(function (){ var myUL = $(this). Siblings(".

Selected"). ToggleClass("showme"); $("ul"). Not(myUL).

RemoveClass("showme"); return false; }); – lauthiamkok Aug 6 '10 at 16:39 thanks for the help! :-)) – lauthiamkok Aug 6 '10 at 16:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions