How is it possible to change the style by a user input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 18

How is it possible to change the style by a user input?

/*var cng = prompt("width size") document. getElementById("test").style.width"" */ I am trying to put style.width"cng" but width is not being changed. It is being changed just by a number entry

23rd May 2019, 4:14 PM
Tahir Usman
Tahir Usman - avatar
5 Answers
+ 3
getElementById("test").style.width = cng + "px" Does this not work? If not i might be on the wrong track and look into it again. It would be nice if you could provide a code sample here on sololearn :)
23rd May 2019, 4:43 PM
Dragonxiv
Dragonxiv - avatar
+ 15
I have tried it but the same size.
23rd May 2019, 4:39 PM
Tahir Usman
Tahir Usman - avatar
+ 15
Thanks Dragonxiv it is working now cng was in ""🙄
23rd May 2019, 4:49 PM
Tahir Usman
Tahir Usman - avatar
+ 1
You have to add "px" after it. Or any other size indication like "em" or others
23rd May 2019, 4:34 PM
Dragonxiv
Dragonxiv - avatar
+ 1
+6
25th May 2019, 9:42 AM
Chowdary Gari Abbai Jampani
Chowdary Gari Abbai Jampani - avatar