javascript - jQuery find all elements with class beneath parent, even in children elements -


here sample html:

<div class="parent">     <div class="searchel"></div>     <div class="searchel"></div>     <div class="child">         <div class="searchel"></div>         <div class="searchel"></div>     </div> </div> 

and here jquery function:

$(function(){     $(".parent>.searchel").each(function(){         $(this).html("found one");     }); }); 

the dom elements end so:

<div class="parent">     <div class="searchel">found one</div>     <div class="searchel">found one</div>     <div class="child">         <div class="searchel"></div>         <div class="searchel"></div>     </div> </div> 

using jquery/javascript, how can search , find elements class .searchel beneath element .parent, if within child element, without searching document globally $(".searchel")?

use space instead of >

   $(function() {       $(".parent .searchel").each(function() {         $(this).html("found one");       });     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  <div class="parent">    <div class="searchel"></div>    <div class="searchel"></div>    <div class="child">      <div class="searchel"></div>      <div class="searchel"></div>    </div>  </div>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -