Saturday, July 25, 2009

[jQuery] Re: jQuery Selectors

make this  simpler by adding a class like "menuActive" to the opened ul. Since you will only ever have one of that class open you can slide that class up and remove the class name before applying the same class to new panel to open

// in click or hover function to switch panels
$(".menuActive").slideUp().removeClass("menuActive);

///  Add the menuActive class to new panel to open and do the slideDown

iceangel89 wrote:
i am actually doing a accordion/sliding menu. here, i want to slide up sibling li > ul that has been open (or displayed). can i simplify this further?      $(this).parent("li").siblings("li:has(ul)").children("ul").slideUp ("fast");  i also noticed that i cannot skip the children() part and do something like      $(this).parent("li").siblings("li:has(ul) ul").slideUp("fast");  why is siblings("li:has(ul) ul") different from siblings("li:has (ul)").children("ul")?    

No comments: