gpt4 book ai didi

jquery - 检查是否存在多个具有相同类的元素

转载 作者:行者123 更新时间:2023-12-03 21:46:06 25 4
gpt4 key购买 nike

想知道是否有任何方法可以检查文档中是否存在具有相同类的元素。

例如:

<div class="panel">panel 1</div>
<div class="panel">panel 2</div>
<div class="panel">panel 3</div>

JS:

if ( $('.panel')[0] ) {
console.log('exists')
}

..但我想检查是否有多个 panel元素存在,至少 2。

最佳答案

尝试使用 length 属性来完成您的任务,

if($('.panel').length > 1) {
console.log('yes, more than one element exist')
}

关于jquery - 检查是否存在多个具有相同类的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com