Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove empty <ul> tag with jquery

Tags:

jquery

I have code like above

     ` <ul id="jsddm">

                            <li><a href="Default.aspx">
                                Menu</a>
                                <ul style="visibility: hidden;">


                                            <li><a href="Content.aspx?ID=153">
                                                SubMenu</a></li>


                                            <li><a href="Content.aspx?ID=152">
                                                SubMenu</a></li>

                                </ul>
                            </li>

                            <li><a href="#">
                                Menu</a>
                                <ul style="visibility: hidden;">

                                </ul>
                            </li>

                </ul>
            </div>`          

I want to romove empty sub "ul" tags which is has got not "li" tag(s) with jquery when my page onload. How can I do? Thanks for help.

like image 968
Kerberos Avatar asked Nov 27 '22 22:11

Kerberos


1 Answers

$('ul').not(':has(li)').remove();
like image 68
Alex Barrett Avatar answered Apr 19 '23 05:04

Alex Barrett