[ACCEPTED]-Jquery - selectors - Selecting every element within a div-jquery-selectors

Accepted answer
Score: 16

The easier jQuery only selection would be 3 $("#divID *"). As you know in CSS a b means all b which is 2 descendant of a and a > b means all b which is direct child of a so #myDiv * means 1 everything that is a descendant of a <div> with id="myDiv".

Score: 6




Score: 3

To get all children and descendents:

$('.SomeClass *')

To get 1 only direct children:

$('.SomeClass > *')
Score: 1

If you want absolutely every element within 1 .Someclass, use:

var allElements = $(".Someclass *");
Score: 1

This works in Chrome:

$(".Someclass *").addClass("testing");


Score: 0

or if you want everything not just direct 1 children. $('.someclass *')

More Related questions