0

I'm tring to move html element on run time.
(1) Call function from code behind. (Button1_Click1 event)

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "myfunction", "testFunc(100,200);", true);

(2) It redirect to JS function. (This function is used to change the location of html attribute)

function testFunc(x,y) {

    document.getElementById('draggable').style.top = x;
    document.getElementById('draggable').style.left  = y;

}

in number 2, if add alert, it's working properly. (It means function is executing successfully)

But html div is not changing. What could be the problem?

This is my HTML code.

 <div>
        <b>This is test page<br />
        </b>
        <div id="draggable" class="ui-icon-image">
           <img id="img1" src="/Resource/location_icon.png" width="27px" height="45px" />
        </div>
     <asp:Button ID="Button1" runat="server"  Text="Button" onclick="Button1_Click1" />
 </div>
2
Contributors
1
Reply
9
Views
3 Years
Discussion Span
Last Post by AleMonteiro
0

Try

document.getElementById('draggable').style.left  = y + "px";

But have in mid that if your element is not absolut positioned, top and left will only act like margins.

Also, if you javascript is working, test only the styles and see if it changes, test step by step, like:

<div id="draggable" class="ui-icon-image" style="top: 200px; left: 100px">
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.