Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Expand and collapse HTML list

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #174011
    jaden5165
    Participant
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $('#example_tree').find('SPAN').click(function(e){
        $(this).parent().find('UL').toggle();
    });
    });
    </script>

    Hi I refer to this link HEREon how to make expansion and collapsed.However,I want to make my list initially will not expand.How can i change the above code.

    #174019
    clokey2k
    Participant

    If you want it to start collapsed just add $('#example_tree').find('SPAN').click(); after binding your onclick code above. This would simulate someone clicking all of the span‘s once – which would hide them.

    i.e.

    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
      $(function(){
        $('#example_tree').find('SPAN').click(function(e){
          $(this).parent().find('UL').toggle();
        });
        $('#example_tree').find('SPAN').click();
    });
    </script>
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.