0

I am looking for a simple script to move an image in JavaScript. Code examples from Google search results are not working for me.

Please help.

2
  • 1
    What exactly do you mean by "move image"? Move it where? Commented Sep 9, 2010 at 20:12
  • What do you exactly mean with "move an image"? That could be anything. Commented Sep 9, 2010 at 20:13

1 Answer 1

3

To directly answer your question, this script will move an image 42 pixels below and 42 pixels to the right of your absolutely-positioned parent (provided that the image was not already in that position).

var img = document.getElementById("IDImage");
img.style.position = "absolute"; // You should style this with CSS, not this script
img.style.top = 42 + "px";
img.style.left = 42 + "px";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you palswim!!! this was very helpful and worked right away. You are a great SO citizen.

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.