Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set position dynamically with jquery

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

    var p = $("#desired_equity");
    var position = p.offset();

  $(document).ready(function(){
    $('#test').css("left", position.left);
    });

Im not sure what I am ding wrong here, any ideas?

like image 618
Thomas Avatar asked Oct 22 '11 22:10

Thomas


1 Answers

You're maybe setting var p before DOM for #desired_equity is ready.

Try

$(document).ready(function(){
    var p = $("#desired_equity");
    var position = p.offset();   
    $('#test').css("left", position.left);
});
like image 124
genesis Avatar answered Sep 21 '22 13:09

genesis