Reputation: 111
I am trying to change a the width value of my div using javascript. Using:
document.getElementById("id").style.width = "25%";
works fine for string literals, but I want to set the value using a variable.
Upvotes: 2
Views: 4972
Reputation: 41757
When concatenating strings and variables javascript will use their string representation, try the following:
var variable = 25;
document.getElementById("id").style.width = variable + "%";
Upvotes: 5