Hi all, I want to change the height of the div tag's content dynamically how can i do this? Thanks in advance.
Here is an example how to do it: <html> <head> <title>Changing height</title> </head> <script type="text/javascript"> function change_height(div){ document.getElementById(div).style.height = "200px"; } </script> <body> <div id="div1" style="border: 1px solid #000000; width: 200px; height: 100px">It is div 1</div> <input type="button" value="Change div 1 height" onclick="change_height('div1');" /> <div id="div2" style="border: 1px solid #000000; width: 200px; height: 150px">It is div 2</div> <input type="button" value="Change div 2 height" onclick="change_height('div2');" /> </body> </html> Code (JavaScript):
thanks for your reply first, But i'm having dynamic text. The div height should changed dynamically so that the text should fix in the div exactly. how can i do this.
Can you write here an example what you want? I think you need something like this: <html> <head> <title>Changing height</title> </head> <script type="text/javascript"> function change_height(div){ alert("The height of "+div+" is "+document.getElementById(div).offsetHeight+" px."); } </script> <body> <div id="div1" style="border: 1px solid #000000; width: 400px">Div1. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> <script type="text/javascript">change_height("div1");</script> <div id="div2" style="border: 1px solid #000000; width: 400px">Div2. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div> <script type="text/javascript">change_height("div2");</script> </body> </html> Code (JavaScript):