How to change div's height and width with Javascript? | Sololearn: Learn to code for FREE!
+ 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.

12th Jan 2017, 10:51 PM
Dima Simonishvili
Dima Simonishvili - avatar
3 Réponses
+ 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! :)
12th Jan 2017, 11:24 PM
–ô–ĺ—Ä–ī–į–Ĺ –ü–Ķ—ā—Ä–ĺ–≤
–ô–ĺ—Ä–ī–į–Ĺ –ü–Ķ—ā—Ä–ĺ–≤ - avatar
+ 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!
13th Jan 2017, 6:04 PM
Dima Simonishvili
Dima Simonishvili - avatar
0
Just as a tip of the hat to jQuery and why it should be learned... $('#demo').css({'width':'100%','height':'auto'});
13th Jan 2017, 12:56 AM
Louis Milotte
Louis Milotte - avatar