Reputation: 37454
function move(direction, el) {
el.style.direction = (el.style.direction+10)+'px';
}
I have this very simple function that moves an element by 10 pixels in a specified direction. Now it errors if i use this, I'm thinking I can't use direction as a variable in this situation. Is this right?
Upvotes: 0
Views: 345
Reputation: 5790
You need to access the style property like this:
function move(direction, el) {
el.style[direction] = (el.style.direction+10)+'px';
}
As long as direction
is a string.
Upvotes: 1