here is the code:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".toexpand").next().hide();
jQuery(".toexpand ul:first").slideToggle();
jQuery(".toexpand").click(function () {
jQuery(this).next().slideToggle('medium');
});
});
</script>
I like to start all the ul next to the .toexpand collapse, BUT NOT THE FIRST ONE… my code dont work, why ?
You can use the
:gt()(greater-than-index) selector, like this:This hides all of the
.toexpandexcept the first one, which has an index of0.With what you have in the question,
.next()actually gets the next sibling of any.toexpandelement, so you’re selecting an entirely different set there, not shifting the.toexpandset around any.