0

I have a few elements who's sizes are variable and I'm trying to move a button with them. My issue is that I don't want to have to hard code it for an unknown number of elements but the code doesn't seem to be working and I'm not sure why.

This is the script that is supposed to move the button

 $("#closeButton").css(moveButton([200, 200]));

and this is the moveButton function

function moveButton(p1){
        var a = (p1[0] + 20) + 'px';
        var b = (p1[1] - 100) + 'px';
        return '{"top": "' + a + '", "left": "' + b + '"}';
    }

1 Answer 1

3

Pass an object, not a string to .css:

function moveButton(p1){
        var a = (p1[0] + 20) + 'px';
        var b = (p1[1] - 100) + 'px';
        return {"top":  a , "left":  b };
    }
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.