user1856596
user1856596

Reputation: 7233

How to select an element with a chain of ids in jQuery?

I have this html:

<div id="outer">
    <div id="inner">...</div>
</div>

In Prototpye I could just use that code to select the inner div by id:

$('#outer #inner');

How would I do that in jQuery? I tried the same selector, but it did not work.

Thanks!

Upvotes: 1

Views: 2595

Answers (1)

James Donnelly
James Donnelly

Reputation: 128791

$('#outer #inner');

Is already valid in jQuery and would select the #inner descendant of #outer.

JSFiddle demo.

You could also use:

$('#outer > #inner');
$('#outer').find('#inner');
$('#outer').children('#inner');

Upvotes: 5

Related Questions