JQuery - get element through id and then through class selector

You could do

$("#div1 span.label")

if you use #div1.label you're actually selecting an element with id div1 AND having the class label.


You almost have it:

$("#div1 .label");

Descendant Selector

Selects all elements that are descendants of a given ancestor.


You could also make it more specific:

$("#div1 > .label");

Child Selector

Selects all direct child elements specified by "child" of elements specified by "parent".


Use a space to indicate the element is a child:

$('#div1 .label');
$('#div2 span');
$('#div2 span.label');

#div1.label would select an element with id div1 and a class of label.