使用jQuery删除第一个列表元素 [英] Delete first list element using jQuery
本文介绍了使用jQuery删除第一个列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下列表:
<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
如何使用jQuery删除此列表的第一个元素(即数字1)并保留其余元素不变?
How can I use jQuery to remove the first element of this list (i.e. the number 1) and leave the remaining elements intact?
我以为这是一个非常简单的解决方案,但事实证明,这比我预期的要难.
I'd have thought this have quite a simple solution but it's proving harder than I expected to answer.
推荐答案
$('#list li').first().remove();
jsFiddle example
参考:
- first
- remove
您还可以使用具有以下功能的纯CSS3(无JavaScript)来实现类似的效果:
You could also accomplish a similar effect using pure CSS3 (no JavaScript) with:
#list li:nth-child(1) {
display:none;
}
这篇关于使用jQuery删除第一个列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文