# How can we get Position of an image and place an other image on that position using jquery

I want to know how can we get exact position of an image and place an other image on that position

excepted positions are top left, top center, top right left center, center, right center bottom left, bottom center, bottom right

For example I have a main image now I put another image on its bottom center.

Is this possible in jQuery?

User .offset() method to get the position of image. Explicitly use .offset().top or .offset().left to get top left coordinate. use .width() and .height() to get width and height of elements. Do some highschool maths and here you go. Voila you get the right answer.

Try experimenting with getBoundingClientRect().

var foo = bar.getBoundingClientRect();


You can set position of something dynamically using the returned variable foo.

foo.left, foo.right, etc.


Mdn for the api

Please try .position() function. The .position() method allows us to retrieve the current position of an element relative to the offset parent.

 var div = \$( "div ");
var position = div.position();
alert("left: " + position.left + ", top: " + position.top);