Javascript: Get div inside of div
I have two divs nested like so:
<div id="upper">
<div id="lower" name="moo">
</div>
</div>
How would I, using jQuery or JavaScript alone, can I get the name o开发者_运维百科f that lower nested div?
var nameValue = $('#lower').attr('name');
But if you really want to use the outer div
to select the inner one:
var nameValue = $('#upper > div').attr('name');
Or
var nameValue = $('#upper #lower').attr('name');
Or
var nameValue = $('#upper').find('#lower').attr('name');
Use .children
.
http://api.jquery.com/children/
精彩评论