![](/img/trans.png)
[英]How to select one specific element (div) from many elements with same class name in with jQuery?
[英]In jQuery, how to test whether an element is the first of many elements of same class?
我有3个div:
<div class='squares' id='div1'></div>
<div class='squares' id='div2'></div>
<div class='squares' id='div3'></div>
使用jQuery,我想将css属性(右边框)应用于所有div(第一个除外)。
我应该使用的if语句是什么? 我想在if语句中使用该类(而不是ID)。
非常感谢。
您可以使用:not()
和:first
选择器:
$('.squares:not(:first)').addClass('border')
要么:
$('.squares:not(:first)').css('border-right', 'value')
在if
语句中使用.is()
:
if (!$(this).is(".squares:first()")) {
// not the first square
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.