首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js获取子元素解决办法

2013-01-23 
js获取子元素举个例子:div idastylewidth: 300px height: 500px background-color: rgb(0, 0, 0)

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()

热点排行