Skip to main content
Home / Code Snippets / jQuery Code Snippets / Click Once and Unbind

Click Once and Unbind

Have something happen on a click event, but only once! Unbind the click handler after the element has been clicked once.

$('#my-selector').bind('click', function() {
       $(this).unbind('click');
       alert('Clicked and unbound!');
});

Also see Ben's comment below for jQuery's .one() function which is essentially the same thing.

icon-link icon-logo-star icon-search icon-star