简体   繁体   中英

Jquery div not selecting

I want to select a div

<section class="grid">
 <div class="results clearfix">
 ....
 </div>
</section>

when i try the following code

 var sortGridList = $(".grid > .results");

It works fine

similarly i have another section

 var sortMapList = $(".map > .results"); console.log(sortMapList.text());
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <section class="map"> <div class="col-sm-4 results"> Sample Text </div> </section>

It does not work

Is there anything wrong in the above code?

Any help or suggestion would be appreciated

Thanks in advance

There isn't anything as such which caused its for not working . Have a look at console for errors if there is any for more clarification .

 var sortGridList = $(".grid > .results"); sortGridList.css("background-color", "yellow"); var sortMapList = $(".map > .results") ; sortMapList.css("background-color", "red");
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <section class="grid"> <div class="results clearfix"> .... </div> </section> <hr> <section class="map"> <div class="col-sm-4 results"> .... </div> </section>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM