Create JQuery toggle using hide and show methods
I tried to hide and show a html element using hide() and show() JQueary methods. I wrote a very simple JQueary script for that. Its working but has a problem. its only work corectlly in one loop. after 1st loop its not working what I expected.
here is my code
------------------------
- <html>
- <head>
- <script src="jquery-1.10.2.min.js"></script>
- <script>
- $(function(){
- $("button").click(function(){
- $("#image").hide("slow",function(){
- $("button").click(function(){
- $("#image").show("slow");
- })
- });
- });
-
- })
- </script>
- </head>
- <body>
- <button>toggle</button><br />
- <img id="image" src="image.jpg"/>
- </body>
- </html>
1st loop (thats what I want)
--------
01) when I click on button, image hide.
02) then again when I click on button image get show.
2nd loop
--------
01) when I click on button, image hide.
02) Image will show automatically without button click. (thats the problem)
Thats the prolem. why its not working like 1st loop continuously? why image start showing automatically after 1st loop? I knew JQuery has toggle() method for that kind of work. but this shoud be work theoritically.
note: My English is not good, because Im not a native english speaker. Im sorry about that.