jquery - If it has children remove href from parent, else -
i have list of menu items sub uls , sub-sub uls. sub-sub uls i'd remove href parent if parent has children.
this have far, not sure how transform if -> else statements.
$('#menu-sidebar-menu > li > ul:has(li) > a').children(['li']).find('a:first').removeattr('href'); <li class="cat-item cat-item-89"><a href="#" title="detailed posts products.">products</a> <ul class='children'> <li class="cat-item cat-item-100"><a href="#" title="detailed posts products.">all</a> </li> <li class="cat-item cat-item-94"><a href="#" title="post products ducati sportbikes.">ducati</a> </li> <li class="cat-item cat-item-91"><a href="#" title="posts products honda sportbikes.">honda</a> <ul class='children'> <li class="cat-item cat-item-104"><a href="#" title="testing">cbr 1000rr</a> </li> <li class="cat-item cat-item-103"><a href="#" title="testing">cbr 600rr</a> </li> </ul> </li> <li class="cat-item cat-item-93"><a href="#" title="post products kawasaki sportbikes.">kawasaki</a>
thank input.
sergio
something this?
$.each($("ul > li"), function (index, obj) { if ($(obj).has("ul").length) { $(obj).has("ul").find("a:first").removeattr("href"); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li class="cat-item cat-item-89"><a href="#" title="detailed posts products.">products</a> <ul class='children'> <li class="cat-item cat-item-100"><a href="#" title="detailed posts products.">all</a> </li> <li class="cat-item cat-item-94"><a href="#" title="post products ducati sportbikes.">ducati</a> </li> <li class="cat-item cat-item-91"><a href="#" title="posts products honda sportbikes.">honda</a> <ul class='children'> <li class="cat-item cat-item-104"><a href="#" title="testing">cbr 1000rr</a> </li> <li class="cat-item cat-item-103"><a href="#" title="testing">cbr 600rr</a> </li> </ul> </li> <li class="cat-item cat-item-93"><a href="#" title="post products kawasaki sportbikes.">kawasaki</a> </li> </ul>