af_inb
af_inb

Reputation: 103

Unbind previous events jquery

I'ts possible to unbind the previos events of a button ,something like that

$("#my-button").on('click',function(){
        $( "#my-button" ).unbind();
        alert('whatever');
      });

Upvotes: 1

Views: 186

Answers (4)

Amol B Lande
Amol B Lande

Reputation: 252

TO unbind event used:

$("#my-button").off('click');

Upvotes: 0

Hiten S
Hiten S

Reputation: 279

$( "#my-button" ).unbind("click");

click can be any event we want to unbind.

unbind need to know which event it has to unbind.

Upvotes: 0

Curiousdev
Curiousdev

Reputation: 5788

You can unbind click using .unbind() or .off()

$( "#my-button" ).unbind( "click" );

Upvotes: 1

Abhi
Abhi

Reputation: 4271

Try this:

$("#my-button").off('click').on('click',function() {
  alert('whatever');
});

Documentation for jQuery off

The .off() method removes event handlers that were attached with .on()

Upvotes: 0

Related Questions