日期:2014-05-16  浏览次数:20376 次

js获取子元素
举个例子:
<div id='a'  style="width: 300px; height: 500px; background-color: rgb(0, 0, 0);">
     <div id='b' style="width: 800px; height: 300px; background-color: rgb(255, 0, 255);">
         <div id='c' style="width: 100px; height: 100px; background-color: rgb(255, 0, 255);">
 </div>
     </div>
 </div>


怎么通过id为a元素获取到id为b的div的width?

document.getElementById('a').firstChild.css('width') 怎么不对啊

------解决方案--------------------

for(var i in document.getElementById('a').childNodes){
if(document.getElementById('a').childNodes[i].nodeType==1){
console.log(document.getElementById('a').childNodes[i].style.width);
}
}

------解决方案--------------------
$('#a').children().first().width()