当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery 获取除某指定对象外的其他对象 ( :not() 与.not())

jQuery 获取除某指定对象外的其他对象 ( :not() 与.not())

2018年11月08日  | 移动技术网IT编程  | 我要评论

 jquery获取除某指定对象外的其他对象

.not()    遍历方法    从匹配元素集合中移除元素

:not()     选择器      选取除了指定元素以外的所有元素。

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

获取ul中除 id="unwanted" 的其他所有 li

  $('li:not(#unwanted)').css('background', 'red');
  $('li').not('#unwanted').css('background', 'red');

总结

以上所述是小编给大家介绍的jquery 获取除某指定对象外的其他对象 ( :not() 与.not()),希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网