15

I am trying to set a box A to jump to the same x-position as box B. How do I do this? I tried the following but it does not work (the second line):

$("#boxa").animate({
   left: $("#boxb").left
}, 1000, function() { });
});

Thanks,

Sam

2 Answers 2

34

either

$('#boxB').css('left');

or

$('#boxB').offset().left;
Sign up to request clarification or add additional context in comments.

Comments

6

For properties specified in pixels, using:

$('#boxB').css('padding-left');

gives a string like: '22px'

Maybe it's better to use:

parseInt($('#boxB').css('padding-left'), 10);

in such cases, which gives a number like 22 .

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.