开发者

Javascript: Get div inside of div

开发者 https://www.devze.com 2023-02-05 20:19 出处:网络
I have two divs nested like so: <div id=\"upper\"> <div id=\"lower\" name=\"moo\"> </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

精彩评论

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