tags:

views:

8

answers:

2

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 ?

A: 

It's hard to determine exactly what you want to do. Could you please rephrase your question?

What I think I take from this is you want to keep the first list element expanded and collapse the rest whenever you call the click method? Also, you do not need to write jQuery in front of all your expressions.

mjw06d
A: 

You can use the :gt() (greater-than-index) selector, like this:

jQuery(".toexpand:gt(0)").hide();

This hides all of the .toexpand except the first one, which has an index of 0.

With what you have in the question,.next() actually gets the next sibling of any .toexpand element, so you're selecting an entirely different set there, not shifting the .toexpand set around any.

Nick Craver