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>


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -