hrishi hrishi - 25 days ago 8
HTML Question

Remove li from ul using id of li

I have drop down where options are in li. I want to dynamically remove li with specific id. Structure is like below

<ul class="es-list" style="top: 305.483px; left: 191.25px; width: 194px; display: block;">

<li id="from_7" class="" value="7" style="display: block;">Adelaide</li>
<li id="from_1" class="" value="1" style="display: block;">Alexandria</li>
<li id="from_17" class="" value="17" style="display: block;">Antwerp</li>
<li id="from_19" value="19" style="display: block;">Aqaba</li>


I tried like

$('#from_7').remove();


but it is not removing li

Answer

You must need to check browser console for errors and i think you are missing the jQuery library file in your code.

$(document).ready(function(){
    $('#from_7').remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="es-list" style="top: 305.483px; left: 191.25px; width: 194px; display: block;">

<li id="from_7" class="" value="7" style="display: block;">Adelaide</li>
<li id="from_1" class="" value="1" style="display: block;">Alexandria</li>
<li id="from_17" class="" value="17" style="display: block;">Antwerp</li>
<li id="from_19" value="19" style="display: block;">Aqaba</li>
</ul>