0
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?

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.