LearnFast.Ninja

Set div position jQuery

Build div with id. call to function that change the position of the div. The main idea is to use the css top, left etc... Try the complete code example.

Step 1: Build div with id.

<div class="My_Div" id="My_Div" onclick="Move_absolute_Div('My_Div')">

    My div

</div>


Step 2: Call to function that change the position of the div.

function Move_absolute_Div(Elm_Id) {

    $("#" + Elm_Id).css({ "position""relative""top""100px""left""100px" });

}


The main idea is:
$("#My_Div").css({ "top""100px""left""100px" });

Complete code:

<!DOCTYPE html>

<html>

<head>

    <title>set div position jquery</title>

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

    <script type="text/javascript" >

        function Move_absolute_Div(Elm_Id) {

            $("#" + Elm_Id).css({ "position""relative""top""100px""left""100px" });

        }

    </script>

</head>

<body>

    <div class="My_Div" id="My_Div" onclick="Move_absolute_Div('My_Div')">

        My div

    </div>

</body>

</html>


Result:


Tags

jquery

jquery-set-position