jquery - javascript preventDefault only on parent item -


i creating drop down nav in javascript. list items have children prevent default action , else. have working when applied default action applied child list items.

here html:

<i id="mobnavtrig" class="fa fa-align-justify fa-2x"></i>     <div class="mobilenav">         <li class="page_item page-item-2"><a href="/">home</a></li>         <li class="page_item page-item-10"><a href="?page_id=10">who are</a></li>         <li class="page_item page-item-25 page_item_has_children current_page_item parent"><a href="?page_id=25">case studies</a>             <ul class='children'>                 <li class="page_item page-item-55"><a href="?page_id=55">barratt developments</a></li>                 <li class="page_item page-item-53"><a href="?page_id=53">care in bathing</a></li>             </ul>         </li>         <li class="page_item page-item-27"><a href="?page_id=27">blog</a></li>         <li class="page_item page-item-29"><a href="?page_id=29">get in touch</a></li>     </div> 

here js:

$( ".mobilenav li.parent" ).click(function(event) {         if($(this).hasclass('page_item_has_children')){             event.preventdefault( );             $(this).addclass('current_page_item');             $(this).find('.children').slidetoggle("fast");         }     }); 

is there missing in above?

in children click have use stoppropagation() stop event bubbling

$( ".mobilenav li.parent .children" ).click(function(e){   e.stoppropagation();  }); 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -