admin管理员组文章数量:1026701
I have two stacked divs.
The outer div has a fixed width with overflow hidden.
The inner div has content that in total can be larger than the outher div.
How can I get the total width of the content of the inner div?
<div id='outer' style='width:100px'>
<div id='inner'>
content
</div>
</div>
When I try $('#inner').width() and the content is larger than outer, it will return the width of the outer div.
I am using Chrome.
/
I have two stacked divs.
The outer div has a fixed width with overflow hidden.
The inner div has content that in total can be larger than the outher div.
How can I get the total width of the content of the inner div?
<div id='outer' style='width:100px'>
<div id='inner'>
content
</div>
</div>
When I try $('#inner').width() and the content is larger than outer, it will return the width of the outer div.
I am using Chrome.
http://jsfiddle/4syEJ/
Share Improve this question asked Feb 10, 2013 at 17:31 Edmund MoshammerEdmund Moshammer 6888 silver badges19 bronze badges3 Answers
Reset to default 4You can get the .scrollWidth
of the parent, which will return what you want.
document.getElementById('outer').scrollWidth
http://jsfiddle/4syEJ/3/
Try :
<div id="outer" style="width:100px">
<div id="inner">
<p id="content">content</p>
</div>
</div>
And
$('#content').width();
you can use .children()
jquery selector like this:
$('#info').html($('#box1').children().width();
$('#box2').children().width();
$('#box3').width());
http://jsfiddle/4syEJ/2/
I have two stacked divs.
The outer div has a fixed width with overflow hidden.
The inner div has content that in total can be larger than the outher div.
How can I get the total width of the content of the inner div?
<div id='outer' style='width:100px'>
<div id='inner'>
content
</div>
</div>
When I try $('#inner').width() and the content is larger than outer, it will return the width of the outer div.
I am using Chrome.
/
I have two stacked divs.
The outer div has a fixed width with overflow hidden.
The inner div has content that in total can be larger than the outher div.
How can I get the total width of the content of the inner div?
<div id='outer' style='width:100px'>
<div id='inner'>
content
</div>
</div>
When I try $('#inner').width() and the content is larger than outer, it will return the width of the outer div.
I am using Chrome.
http://jsfiddle/4syEJ/
Share Improve this question asked Feb 10, 2013 at 17:31 Edmund MoshammerEdmund Moshammer 6888 silver badges19 bronze badges3 Answers
Reset to default 4You can get the .scrollWidth
of the parent, which will return what you want.
document.getElementById('outer').scrollWidth
http://jsfiddle/4syEJ/3/
Try :
<div id="outer" style="width:100px">
<div id="inner">
<p id="content">content</p>
</div>
</div>
And
$('#content').width();
you can use .children()
jquery selector like this:
$('#info').html($('#box1').children().width();
$('#box2').children().width();
$('#box3').width());
http://jsfiddle/4syEJ/2/
本文标签: jqueryJavascript Getting the width of childelementsStack Overflow
版权声明:本文标题:jquery - Javascript: Getting the width of child-elements - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745649170a2161209.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论