Reputation: 2851
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?
Upvotes: 24
Views: 100782
Reputation: 776
You need to add a space between the select the li element,
$('#second li').remove(); // when referencing by id
or
$(".second li").remove(); // when referencing by class
Upvotes: 1
Reputation: 1
if you want remove an <li>
with ID try :
$('#yourlist #yourli').remove()
;
otherwise, if you would remove an <li>
based on the content you can use :
$('#yourlist li:contains("TextToRemove")').remove();
Upvotes: 0
Reputation: 1911
$('#ulId #secondli').remove();
Select the container #ulId
and then the list item #secondli
. You had forgotten to add the ID tag before the second li.
Upvotes: 0
Reputation: 207861
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/
Upvotes: 58