Text is ...">

Access div height in javascript

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 )above div in javascript? I tried

$('div').height()and $('div').css("height");come back auto.

+5
source share
4 answers

You can try .innerHeight()or .outerHeight(), depending on what you want.

+7
source

try using

$('div').innerHeight()

or

$('div').outerHeight()
+1
source

var divs = document.getElementsByTagName('div');
if(divs.length>0)
     divs[0].offsetHeight;
+1

:

document.getElementsById('myElementId').offsetHeight; // Without jQuery

$('#myElementId').outerHeight(); // With jQuery 

1: externalHeight (true) , http://api.jquery.com/outerHeight/

Note 2: innerHeight () returns the current calculated height for the first element in the set of matched elements, including the indent, but not the border.

Note 3: $ ('div'). height () or $ ('div'). css ("height") returns only the css value.

0
source

All Articles