On click - jQuery event problems -


i'm trying create function, after clicking on button, open search box, , after clicking again on same button close it.

i have build this:

 $("#searchbutton").click(function(){       $("#searchbox").animate({top: '0px'}, 500),          $(this).click(function(){         $("#searchbox").animate({top: '-47px'}, 500)             });         }); 

it works fine first time after click on it. if i'll click on again re-open without refreshing page button automatically hide.

why happening?

thank in advance

dom

your problem never unbind first click handler.

the best solution use toggle handler, this:

$("#searchbutton").toggle(     function () { $("#searchbox").animate({top: '0px'}, 500); },      function () { $("#searchbox").animate({top: '-47px'}, 500); } ); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -