在 jquery 中只选择一个类
Select only one single class in jquery
说我有多个类名为item。
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
但我只想展示一个,顺序并不重要。我该怎么做?
$('.item').show() // this will show all of them
可以使用以下任一方法从匹配的集合中选择特定元素:
// show the first .item only
$('.item:first').show();
$('.item').first().show();
// show the last .item only
$('.item:last').show();
$('.item').last().show();
// show the second .item only
$('.item:eq(1)').show();
$('.item').eq(1).show();
请注意,eq
采用一个参数,该参数是要定位的元素的索引。
$('.item').eq(0).show() // it will display first item
相关文章:
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- 按照选项卡索引的顺序循环一个jQuery选择
- 在创建对象后附加一个jquery事件
- 我需要一个jQuery函数来只工作在700px以上的屏幕大小,无法在我的代码中发现错误
- 一个jquery验证器方法,它不接受纯数字或纯特殊字符,但接受上面是否有字母
- 我做了一个jquery幻灯片,但没有;我工作不好,我该怎么办
- 我创建了一个jQuery幻灯片,但它一直在重复相同的图像
- 是preventDefault()一个jQuery函数或javascript函数
- 使用一个 jquery 代码关闭多个模态
- 如何在 elfinder(一个 jquery 文件管理器插件)中只显示文件夹列表
- 遍历下一个和上一个 jQuery 选项卡
- module.exports一个jQuery插件
- 有没有一个jquery marquee插件/脚本可以处理不同宽度的图像
- 一个jquery初始化中有多个类
- 如何从其中的另一个jquery脚本运行.load()
- 从 javascript 数组创建一个 Jquery 数组
- 第一个jquery事件正在发生,但没有发生第二个事件
- 向一个jQuery/DOM元素添加一个函数
- 我们如何在jQuery Datatable调用结果中启动另一个jQuery插件,而不是页面就绪函数
- 我可以自动生成一个jquery块,对不同的元素做同样的事情吗