jQuery implements the method of unbinding the click event after clicking the button only once

  • 2020-06-22 23:49:55
  • OfStack

This article describes the jQuery implementation of the button click once and then cancel the click event binding method. Share to everybody for everybody reference. Specific implementation methods are as follows:


<input type="button" id="my-selector" value=" Only click 1 time " />
<script>
$('#my-selector').bind('click', function() {
    $(this).unbind('click');
    alert('Clicked and unbound!');
});
</script>

Hopefully, this article has been helpful in your jQuery programming.


Related articles: