Change image src of imagebutton using jquery 1.4.4 -
i tried change image src of imagebutton using jquery fails change background.
i have tried below script or that:
$(document).ready(function () { $('#<%=imagebuttonid.clientid%>').click(function () { $('#<%=imagebuttonid.clientid%>').attr("src", "mobile/images/writelogbook_icon.png"); }); });
i have tried object.css("backgroundimage","path"); but, fails. please suggest me. using jquery 1.4.4 min
edit: relavent code html:
<input type="image" name="imagebuttonid" id="imagebuttonid" src="images/admin.png" /> $('#imagebuttonid).click(function () { $(this).attr('background-image', 'images/customer.png'); });
thanks,
naresh goradara
you should try this:
<asp:imagebutton id="imagebuttonid" runat="server" src="images/admin.png"> </asp:imagebutton> <script type="text/javascript"> $(document).ready(function () { $('#<%=imagebuttonid.clientid%>').click(function (e) { $('#<%=imagebuttonid.clientid%>').attr("src", "images/customer.png"); e.preventdefault(); }); }); </script>
this works fine in test-project. remember e.preventdefault, , passing in e in click-function. causes image-button not post server, hence refreshing page.
if page refreshes, imagebutton have original image again.
Comments
Post a Comment