Jquery - selectors - select each item in a div

Is there an easy way to select all elements in a div (or any other element) using jQuery ?
This week I was looking for a watch, and I keep banging my head on the keyboard.

 <div class="Someclass"> <img src="" title="" /> <ul> <li></li> <li><a href="" alt="" /></li> </ul> </div> 

I want an easy way to select all the elements inside .Someclass without having to call each element.

+4
source share
6 answers

A simpler jQuery choice would be $("#divID *") . As you know, in CSS, ab means that all b that are descendants of a and a > b mean all b that are direct children of a , so #myDiv * means everything that is a descendant of <div> with id="myDiv" .

+12
source

http://api.jquery.com/children/

 $('div.someclass').children(); 
+4
source

To get all children and descendants:

 $('.SomeClass *') 

To receive only direct children:

 $('.SomeClass > *') 
+1
source

If you want absolutely every element inside .Someclass, use:

 var allElements = $(".Someclass *"); 
+1
source

This works in Chrome:

 $(".Someclass *").addClass("testing"); 
+1
source

or if you want everything to not just guide the children. $('.someclass *')

0
source

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


All Articles