JavaScript set scrollHeight

In JavaScript, what is the proper way to set scrollHeight of one element to an element of another element? Direct appointment is not affected. Thanks Greg

+4
source share
1 answer

This is not possible directly. ScrollHeight is a read-only property that contains the total height of the content of the element in pixels.

If you have element A and want to have element B with the same scrollHeight as element A, make element B have one child div (move all the contents of the previous element B as children of the div) that is set to :

width : 100%; overflow : hidden; 

and using javascript, set the DIV height to scroll the Height of the A element (in pixels):

 document.getElementById('B').childNodes.item(0).style.height = document.getElementById('A').scrollHeight + 'px'; 
+8
source

All Articles