Satish Sharma
Satish Sharma

Reputation: 9635

remove parent <li> if child <>ul <li> not found

i am generating menu dynamically using php in my project in ul li. menu are generating as follows.

<ul id="css3menu1" class="topmenu">
    <li class="toproot"><a href="#"><i class="user"><span>User</span></i></a>
        <ul>
           <li><a href="some link">Create User</a></li>
           <li><a href="some link">List User</a></li>
        </ul>
    </li>

   <li class="toproot"><a href="#"><i class="user"><span>Group</span></i></a>
        <ul>
            <li><a href="some link">Create Group</a></li>
            <li><a href="some link">Group List</a></li>
        </ul>    
    </li>

     <li class="toproot"><a href="#"><i class="user"><span>Settings</span></i></a>
        <ul>
            <!--links are not generated here -->
        </ul>    
    </li>                   

</ul>

now the problem is that i want to remove third li of setting main menu beacause of it has no submenu. i searching for jquery code for this implementation. i have use php to display or display not main menu. but want to implement in jquery/js. thanks in advance

Upvotes: 0

Views: 293

Answers (2)

Bhoomi
Bhoomi

Reputation: 1

You can code somthing like this, using jquery.

if ($('#mylist li').length == 0){
Do Code for removing elements
}

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Try

$('.topmenu li.toproot:not(:has(ul))').remove()

Upvotes: 4

Related Questions