Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI
The jquery 'slideToggle' do not working with the html image. But it work for
html button and textbox.what is the reason?

the image control as below

HTML
<input type="image" id="flip" src="~/image/history-button.gif"/>



jquery as below

jquery
$(document).ready(function () {
            $("#flip1").click(function () {
                $("#panel").slideToggle("slow");
                });

});



Thanks..
Posted
Updated 21-Feb-13 19:07pm
v3
Comments
Sergey Alexandrovich Kryukov 22-Feb-13 1:01am    
ASP.NET has nothing to do with jQuery, in this respect. There is no "ASP.NET image buttons"; on the client site, this is just some HTML. jQuery know nothing about ASP.NET or any other server-side technology.
—SA
hasbina 22-Feb-13 1:07am    
i changed the qstn.
Surendra0x2 22-Feb-13 1:13am    
html image?what u saying dude ?ur question is not clear what ur trying to ask.

i think it is just because jquery loses its state after postback because a postback will occur on imagebuttonclick which is server side control.
can't u use ?


HTML
<a class="flip1" href="#" title="Comment"><img src="imageurl"/></a>


JavaScript
$(document).ready(function () {
            $(".flip1").click(function () {
                $("#panel").slideToggle("slow");
                });
 
});
 
Share this answer
 
v3
Comments
hasbina 22-Feb-13 1:29am    
@Surendra0x2

Thank you sir..thank you...
Surendra0x2 22-Feb-13 1:37am    
I'm Glad it helped you :)
Happy Coding :)
Put your image tag in anchor tag like
<a href="#" id="aflip">
   <input type="image" id="flip" src="~/image/history-button.gif" /> 
</a>

and write jquery like

$(document).ready(function () {
         $("a#aflip").click(function () {
             $("#panel").slideToggle("slow");
             });

});


this may work
 
Share this answer
 
Important thing you should know while using Jquery is PostBack property
When postback occurse JQuery code will get its original values..
So you should prevent postback to see the functionality it..

HTML
<input type="image" id="flip" src="~/image/history-button.gif"/>

JavaScript
$(document).ready(function () {
            $("#flip").click(function (e) {
                $("#panel").slideToggle("slow");
                 e.preventDefault();
                });
 
   });

Where e.preventDefault() will avoid paostback.. So when you are using buttons use e.preventDefault() to prevent postback ( If postback is no necessory )..
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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