1

How do I set y location using jQ offset().top?

$(#ele).offset().top = 123

Do I need to include 'px' or other appropriate unit in there?

2
  • $('#ele').css('top', '123px'); Commented Dec 16, 2013 at 2:37
  • I'm trying to avoid using css here, is there another way? Commented Dec 16, 2013 at 2:38

1 Answer 1

5

From the jQuery documentation

.offset( coordinates )

coordinates: An object containing the properties top and left, which are integers indicating the new top and left coordinates for the elements.

The properties top and left are integers, you don't need to include the 'px' unit

$("#ele").offset({ top: 123 });
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.