How can set the offset using JavaScript ?
The offset() method set or returns the offset coordinates for the selected elements, relative to the document. When used to return the offset: This method returns the offset coordinates of the FIRST matched element. It returns an object with 2 properties; the top and left positions in pixels.
The offsetLeft property returns the left position (in pixels) relative to the parent. The returned value includes: the left position, and margin of the element. the left padding, scrollbar and border of the parent.
Returns the number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.
You set the left
and top
CSS values.
$("#myEl").css({"position":"absolute","left":"100px","top":"100px"});
var myEl = document.getElementById("myEl);
myEl.style.position = "absolute";
myEl.style.left = "100px";
myEl.style.top = "100px";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With