admin管理员组文章数量:1391991
I have a div :
css
div { width: 200px; height:auto }
markup
<div contenteditable="true"> Text is editable </div>
Now what should i do to access the height ( numeric value )
of the above div in javascript ? I tried
$('div').height()
& $('div').css("height");
both returns auto
.
I have a div :
css
div { width: 200px; height:auto }
markup
<div contenteditable="true"> Text is editable </div>
Now what should i do to access the height ( numeric value )
of the above div in javascript ? I tried
$('div').height()
& $('div').css("height");
both returns auto
.
- 3 Both work fine jsfiddle/sySFk – Musa Commented Jul 16, 2012 at 8:06
4 Answers
Reset to default 7You may want to try .innerHeight()
or .outerHeight()
, depending on what you want.
try using
$('div').innerHeight()
or
$('div').outerHeight()
Try This
var divs = document.getElementsByTagName('div');
if(divs.length>0)
divs[0].offsetHeight;
For returning the NUMERIC height value :
document.getElementsById('myElementId').offsetHeight; // Without jQuery
$('#myElementId').outerHeight(); // With jQuery
Note 1: outerHeight(true) returns the size with margin and padding inclued, more informations on http://api.jquery./outerHeight/
Note 2 : innerHeight() returns the current puted height for the first element in the set of matched elements, including padding but not border.
Note 3: $('div').height() or $('div').css("height") returns the css value only.
本文标签: jqueryAccessing the height of div in javascriptStack Overflow
版权声明:本文标题:jquery - Accessing the height of div in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744596616a2614817.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论