I\'m trying to use jQuery to detect the position of a div (#olddiv
), so I can use that position to place another div (#newdiv
) exactly below it. The ri
I've used offset() to position elements dynamically. Try this:
var offset = $('#olddiv').offset();
var height = $('#olddiv').height();
var width = $('#olddiv').width();
var top = offset.top + height + "px";
var right = offset.left + width + "px";
$('#ID').css( {
'position': 'absolute',
'right': right,
'top': top
});
also don't forget to bind this to the window.onresize
event if you need it to scale when the user resizes the window.
UPDATE: another thought - does this have to be positioned absolutely? Why not just insert the div after the other in the DOM?
$('#olddiv').after($('#ID').html());
then just make sure they are the same width.