+ 3
How to change div's height and width with Javascript?
Hello everyone, I need to change div's width and height only using Javascript. In html I've one div and three input fields, which sets div's height width and color. Last one is working, but I can't change height and width which are set in input fields. Please help.
3 Answers
+ 4
<!DOCTYPE html><html>
<head></head><body>
<style>
#demo {
border: 1px solid black;
}
</style>
<div id="demo">
<form>
<input type="text"><br>
<input type="text"><br>
<input type="submit">
</form>
</div>
<script>
document.getElementById("demo").style.width = "300px"; // width
document.getElementById("demo").style.height = "100px"; // height
</script>
</body></html>
Hope I helped! :)
+ 2
@Louis thanks for this tip. I'll use it in future. But for now I needed only pure Javascript.
@ŠŠ¾ŃŠ“Š°Š½ Thanks for this great example, it helped me very much!
0
Just as a tip of the hat to jQuery and why it should be learned...
$('#demo').css({'width':'100%','height':'auto'});