如何删除< li>来自< ul>由ID? [英] How do you remove <li> from a <ul> by Id?
本文介绍了如何删除< li>来自< ul>由ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
<ul id="ulId">
<li id="firstli">
</li>
<li id="secondli">
</li>
</ul>
并且我正在尝试删除secondli
.
这是我根据一些阅读尝试过的.
This is what I have tried based on some reading.
$('#ulId secondli').remove();
和
$('#ulId > secondli').remove();
,但是这两种方法不起作用.有什么建议吗?
but these 2 methods did not work. Any suggestions?
推荐答案
尝试一下:
$('#secondli').remove();
在jQuery中,您引用的元素的ID前面带有#
.请参见 http://api.jquery.com/id-selector/
In jQuery, you refer to the ID of an element with a #
in front of it. See http://api.jquery.com/id-selector/
这篇关于如何删除< li>来自< ul>由ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文