1、filter为过滤方法,过滤出想要选择的元素
描述:选中class类名为box的div并添加背景色红色
<body> <div class="box">div1</div> <div>div2</div> </body> <script type="text/javascript"> $('div').filter('.box').css('background','red') </script>
执行效果、:
2、not方法和filter方法相反
<body> <div class="box">div1</div> <div>div2</div> </body> <script type="text/javascript"> $('div').not('.box').css('background','red') </script>
执行效果:
3、has:包含
描述:查找包含span标签的div
<body> <div class="box"><span>div1</span></div> <div>div2</div> </body> <script type="text/javascript"> $('div').has('span').css('background','red') </script>
执行结果: