开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜