Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all ,

I am trying to place a button under another button using jquery but it is staying in its place.Knowing that when alerting its top and left they are giving me correct values as i want.So how to fix it ?

Here is the code :

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

</head>
<body>
    <form action="">
    <input type="button" id="placeit" value="placeit" name="btn2" />
    <input id="btn1" type="button" name="btn1" value="button" />
    <p>
    </p>
    </form>

    <script type="text/javascript">
        var p = $("#btn1");
        var position = p.position();
        var place = document.getElementById("placeit");
        place.top = position.top + 30;
        place.left = position.left;
        alert(place.top);
        alert(place.left);
        $("p:last").text("left: " + position.left + ", top: " + position.top);
    </script>

</body>
</html>
Posted

1 solution

Take a look at this:
http://manifestwebdesign.com/developer-resources/setting-offset-with-jquery/[^]

Read the script carefully, and you'll see what you need to do. (hint: css position[^])

Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Manas Bhardwaj 30-Jul-11 13:56pm    
my 5!
Espen Harlinn 30-Jul-11 14:01pm    
Thank you, Manas!
mhamad zarif 30-Jul-11 14:10pm    
my 5.It was a solution for my problem.thanks you.
mhamad zarif 30-Jul-11 14:09pm    
It is working like magic ! thank you my friend.
Espen Harlinn 30-Jul-11 14:12pm    
Good :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900