javascript - Jquery multiple selectors and multiple contains -


can search div multiple selectors each contains in 1 jquery string? needs , not or search .

$('.row .people:contains("james") .tags:contains("episode")') 

the above selection should return first div below.

<div class="row">   <span class="people">james</span>   <span class="tags">episode</span> </div> <div class="row">   <span class="people">bill</span>   <span class="tags">episode</span> </div> <div class="row">   <span class="people">james</span>   <span class="tags">podcast</span> </div> 

you can use jquery's .has() check if element contains descendants. can nest :contains within .has() statement.

that'll allow check if .row contains span text.

then can add second .has() statement check has both spans matched text.

note in example html, doing check way describe overcomplicating things because .row:first-child, assuming need check things way, way go.

example:

$('.row').has('.people:contains("james")').has('.tags:contains("episode")').addclass('highlighted');
.row.highlighted {    background-color: red;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="row">    <span class="people">james</span>    <span class="tags">episode</span>  </div>  <div class="row">    <span class="people">bill</span>    <span class="tags">episode</span>  </div>  <div class="row">    <span class="people">james</span>    <span class="tags">podcast</span>  </div>


Comments

Popular posts from this blog

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Create a stacked percentage column -