Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a div and a button. After drag&drop this div object to other position. I want that when I click button, that div object will change style with new position has just changed. I have already processed drag&drop.

Div object changed postion:
XML
<div id="divml5" class="dragDiv1"  runat="server" style="width:40px;height:40px;position:relative;
                                                                left:120px;top:60px;">
        <table>
            <tr>
                 <td>
                    <h5 id="h5ml5" class="handler" runat="server"
                            style="background-image:url('../../Images/image.jpg');
                                    vertical-align:middle;width:40px; height:40px;background-repeat:no-repeat;"></h5>
                </td>
            </tr>
        </table>
    </div>


Button
C#
<button type="button" id="btn" runat="server" onclick="changeStyle();">ChangeStyle</button>



and I have paragrahp code to process change style of that div object:

C#
var divml5 = document.getElementById("divml5");
        var h5ml5 = document.getElementById("h5ml5");
        function changeStyle(){
           
            divml5.style.backgroundImage = "url('../Images/clientRed.jpg')";
            h5ml5.style.backgroundImage = "url('../Images/clientRed.jpg')";



I think I can implement as I want, but it can't process.
Posted

Did you try onClick instead? (Notice the capital C).

If it still does not work it could be since your button has runat="server" it will do a postback when you click it. Either use
onClick="changeStyle();return false"
to prevent resubmit or do not use runat="server".
 
Share this answer
 
Comments
khidotlua 22-Nov-10 23:13pm    
onClick="changeStyle()", but div object not change style.
Have you checked if your javascript is correct? or whether the background image URL is correct?
 
Share this answer
 

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