JS how to increase a value by x onclick | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JS how to increase a value by x onclick

Example; div width = 10px; When u click on this button, the div width increases by 5 (15), if u click it again it increases by 5 again (20)... I'm just experimenting on this code: https://code.sololearn.com/WVMu0BA0xtR5/?ref=app

25th Jul 2019, 5:02 AM
Ginfio
Ginfio - avatar
1 Answer
+ 3
Rather than increasing the value of wi within the assignment of the new width, you could just do the following: wi = 50; function width(){ wi += 10; pap.style.width = wi+"px"; }
25th Jul 2019, 5:05 AM
Faisal
Faisal - avatar