Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove <li> from a <ul> by Id?

Tags:

jquery

I have:

<ul id="ulId">
    <li id="firstli">
    </li>
    <li id="secondli">
    </li>
</ul>

and I am trying to remove secondli.

This is what I have tried based on some reading.

$('#ulId secondli').remove();

and

$('#ulId > secondli').remove();

but these 2 methods did not work. Any suggestions?

like image 697
Pittfall Avatar asked Mar 25 '13 21:03

Pittfall


People also ask

How do you add a Li element to UL?

To add new li to ul on click with JavaScript, we can call the appendChild method. const ul = document. getElementById("list"); const li = document. createElement("li"); li.


1 Answers

Try this:

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

In jQuery, you refer to the ID of an element with a # in front of it. See http://api.jquery.com/id-selector/

like image 138
j08691 Avatar answered Sep 21 '22 19:09

j08691