jQuery ubinding a click event after first click

This article looks at using jQuery unbind to remove a click event after the first click. As an example we'll be creating a simple search box the gets displayed on first click and would do the search on second click. As always don't forget to include jQuery!

HTML

<input type='text' id='searchBox' />
<input type='button' id='searchButton' value='search' />

jQuery

$( document ).ready(function() {

    $('#searchButton').click(function(event)
    {
        $('#searchBox').fadeIn('slow');
        $(this).unbind(event);
        return false;
    });

});

Demo

Sign Up
comments powered by Disqus
Sign Up

Popular Tags

350x250

Need a web developer?

If you'd like to work with code synthesis on your next project get in touch via the contact page.