使用 jQuery 删除第一个列表元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12232431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:27:07  来源:igfitidea点击:

Delete first list element using jQuery

jquery

提问by dplanet

I have the following list:

我有以下清单:

<ul id="list">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>    
</ul>

How can I use jQuery to remove the first element of this list (i.e. the number 1) and leave the remaining elements intact?

如何使用 jQuery 删除此列表的第一个元素(即数字 1)并保持其余元素完好无损?

I'd have thought this have quite a simple solution but it's proving harder than I expected to answer.

我原以为这有一个非常简单的解决方案,但事实证明它比我预期的要难回答。

回答by j08691

$('#list li').first().remove();

jsFiddle example

jsFiddle 示例

Ref:

参考:

You could also accomplish a similar effect using pure CSS3 (no JavaScript) with:

您还可以使用纯 CSS3(无 JavaScript)实现类似的效果:

#list li:nth-child(1) {
    display:none;
}?

回答by Rafael Adel

$("#list li:first-of-type").remove();