如何删除< li>来自< ul>由ID? [英] How do you remove <li> from a <ul> by Id?

查看:73
本文介绍了如何删除< 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/

这篇关于如何删除&lt; li&gt;来自&lt; ul&gt;由ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆