JQuery took several selectors

Is there a way to make the selectors required here:

var $el = $('.top').children(':gt(2), :contains("word")');

According to Multiple Selectors , it will find elements that match either of these two selectors.

How to find elements that match all , not any of them selectors ?jQuery( "selector1, selector2, selectorN" )

+4
source share
2 answers

The easiest way is to combine the selector:

$('.a.b.c').css({'color':'blue'});

Another way would be to use the function filter()with the first selector and add selector 2 to N inside filter()using the function is()- see the demo below:

/*This combines the three selectors .a .b and .c*/
$('.a').filter(function(){
  return $(this).is('.b') && $(this).is('.c')
}).css({'color':'blue'});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="a">1</div>
<div class="b">2</div>
<div class="c">3</div>
<div class="a b">4</div>
<div class="a c">5</div>
<div class="b c">6</div>
<div class="a b c">7</div>
Run codeHide result
+1

:

var $el = $('.top').children(':gt(2):contains("word")');

+2

Source: https://habr.com/ru/post/1667474/


All Articles