Javascript Get Style And Increment
I'm trying to make a slider that changes the margin-left attribute in the external css onclick. So I need to get the attribute and then set the new attribute. here is my code: <
Solution 1:
In Javascript, the .
operator does not concatenate strings.
Use the +
operator instead:
document.getElementById(divName).style.marginLeft = y + 'px';
You also probably need to pass marginLeft
as a string, not a name (unless there is a variable in scope that is named marginLeft
and set to "marginLeft"
):
var y = x.currentStyle["marginLeft"];
And:
var y = document.defaultView.getComputedStyle(x, null).getPropertyValue("marginLeft");
Post a Comment for "Javascript Get Style And Increment"