Problems with accordion based on slideToogle() and slideUp()
Hey everybody,
at first let me say hello to everybody cause i am new in this forum. I am still using jquery a while but wouldn't rate my jquery knowledge very good.
Actually i am trying to build an accordion based on slideToogle() and slideUp()... The only problem atm is that opened <ul class="children">...</ul> wrappers(yes they are the tooglin elements...) doesn't get closed, i think i missunderstud .siblings() and the hierarchy...?
I have the following structure:
Rendered HTML
- <div id="wrapper">
- <ul>
- <li class="item">
- <a href="">Link I</a>
- <ul class="children">
- <li><a href="">I-1</a></li>
- ...
- <li><a href="">I-8</a></li>
- </ul>
- </li>
- <li class="item">
- <a href="">Link II</a>
- <ul class="children">
- <li><a href="">II-1</a></li>
- ...
- <li><a href="">II-4</a></li>
- </ul>
- </li>
- <li class="item"><a href="">Link III</a></li>
- <li class="item"><a href="">Link IV</a></li>
- </ul>
- </div>
JS (.css() only added for debugging reasons)
- <script>
- $("#wrapper a").mouseover(function () {
- $(this).next("ul.children").slideToggle("slow")
- .siblings("ul.children:visible").css('background-color', 'red').slideUp("slow");
});
</script>
If anybody can give me a hint i would be really happy...
I also asked myself if there is the possibility to detect if the first level <li>'s have a <ul class="children">...</div> inside - you can see it in my example that the last 2 first level <li>'s doesn't have any included. I would make sense to handle that 2.
Thanks in advance and many regards,
Jan