Reputation: 1808
How can I get an element by id, and then inside this element get all elements by class name using jQuery? It's pretty easy to do this using the standard JS functions getElementById() and getElementsByClassName(), but unfortunately IE 7-8 do not support the latter.
Upvotes: 21
Views: 51160
Reputation: 39709
In jquery you can get element by id as $('#some_id')
and get element by class name as $('.some_class_id')
please see jquery api for more details.
and to access inside elements you can do it like this $('#some_id .some_class')
Upvotes: 2
Reputation: 253485
You have a few options:
The first, using a css selector:
$('#idOfElement .classNameOfElements');
Or using find()
:
$('#idOfElement').find('.classNameOfElements');
Or using selector context:
$('.classNameOfElements', '#idOfElement');
It's worth noting that using the context (final) approach causes jQuery to internally implement the find()
method.
References:
Upvotes: 38