CK8 CK8 - 2 days ago 4
HTML Question

Bootstrap Nav bar, remove list items dynamically using jQuery

I am trying to use jQuery to remove the list items of Bootstrap Nav Bar by using the following jQuery code. The code run but the list items didn't remove. Please help! -The following are the html code and Javascript code :

<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li id="home" class="active">
<a aria-expanded="false" role="button" href="Home.html"> Home</a>
</li>
<li id="add" class="inactive">
<a aria-expanded="false" role="button" href="Add.html">Add</a>
</li>
<li id="search" class="inactive">
<a aria-expanded="false" role="button" href="Search.html">Search</a>
</li>
<li id="admin" class="inactive">
<a aria-expanded="false" role="button" href="Admin.html">Admin</a>
</li>
<li id="my" class="inactive">
<a aria-expanded="false" role="button" href="my.html">My Profile</a>
</li>

</ul>
</div>
<script>
$(document).ready(function() {
if (sessionStorage.getItem("role_admin") != "1") {
$("#add").remove();
$("#admin").remove();
}
});
</script>

Answer

First please look at the second <script> tag, you're not closing it.