Well, it depends, if all you need is to position the div and then nothing else, you do not need to use a java script for this. You can only achieve this with CSS. The important thing is which container do you want to position your div, if you want to position it relative to the body of the document, then your div should be absolute and its container should not be relative or absolute, in this case your div will be located relative to the container.
Otherwise, with Jquery, if you want to position the element relative to the document, you can use the offset () method.
$(".mydiv").offset({ top: 10, left: 30 });
if relative to the offset of the parent position, the parent is relative or absolute. then use the following ...
var pos = $('.parent').offset(); var top = pos.top + 'no of pixel you want to give the mydiv from top relative to parent'; var left = pos.left + 'no of pixel you want to give the mydiv from left relative to parent'; $('.mydiv').css({ position:'absolute', top:top, left:left });
Ehtesham Jul 23 '11 at 20:27 2011-07-23 20:27
source share