thecodedeveloper.com
thecodedeveloper.com

Reputation: 3240

hide sub menu with jquery by default and after click sub menu show and hide

this is my html code

<ul class="list">
    <li class="pagenav">
    <a title="Government" href="#">Government</a>
        <ul>
            <li class="page_item page-item-14"><a href="#">Code of Ordinances</a></li>
            <li class="page_item page-item-5267"><a href="#">Finance</a>
                <ul class="children">
                    <li class="page_item page-item-16"><a href="#">Fiscal Year</a></li>
                    <li class="page_item page-item-5280"><a href="#">Comprehensive</a></li>
                </ul>
            </li>
            <li class="page_item page-item-5267"><a href="#">Finance year</a>
                <ul class="children">
                    <li class="page_item page-item-16"><a href="#">Year</a></li>
                    <li class="page_item page-item-5280"><a href="#">Comprehensive year</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

by default show like that

Government

Code of Ordinances

Finance

Finance year

and after click Finance show like that

Government

Code of Ordinances

Finance

Fiscal Year

Comprehensive

Finance year

i mean to say i want to hide sub menu of Finance and Finance year by default and after click Finance and Finance Year that time sub menu show & hide

Upvotes: 1

Views: 2272

Answers (2)

odiszapc
odiszapc

Reputation: 4109

<style>
  li.pageitem ul.children {
  display:none;
}
</style>

<script>
$('li.pageitem').click(function(){
  $(this).find('ul.children').toggle();
});
</script>

Upvotes: 0

Ohgodwhy
Ohgodwhy

Reputation: 50798

$('.page_item .children').hide(0);

$('.page_item').click(function(){
  if($('.children').hasClass('vis')){
    $('.children', this).removeClass('vis');
    $('.children', this).hide();       
  }else{
    $('.children', this).addClass('vis');
    $('.children', this).show();
  }
});

Upvotes: 1

Related Questions