Set position dynamically using jquery

I need to use the offset coordinates of one position to dynamically set the position of the second element ("#test").

var p = $("#desired_equity"); var position = p.offset(); $(document).ready(function(){ $('#test').css("left", position.left); }); 

I'm not sure I'm wrong here, any ideas?

+7
source share
1 answer

You may have configured var p before the DOM for #desired_equity is ready.

Try

 $(document).ready(function(){ var p = $("#desired_equity"); var position = p.offset(); $('#test').css("left", position.left); }); 
+9
source

All Articles