Alex Rivera | Logout

Get elements by class name inside another element with jQuery

Asked 2011-08-10T11:50:09.927
21

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.

Edit
Report

2 Answers

37

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:

answered 2011-08-10T11:52:38.310
2

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')

answered 2011-08-10T11:54:33.857

Your Answer