How to avoid and return an event in jquery when you specify a new event?

I need to overwrite the events but, the application has an option to return the original events to each element of the document. Any ideas?

For example:

    <div class="mydiv">
    </div>

    $(document).delegate( '.mydiv', click', function () { 
        alert('This is the original event my event!');
    });

    $(document).delegate( '.mydiv', 'click', function() {
       alert('Do this and ignore de previous...');
       // For example: How to return the original event when mouseleave event will executed?
    });

    $(document).delegate( '.mydiv', 'mouseleave', function() {
//       return the original event of mydiv 
    });

Upvotes: 0

Views: 47

Answers (2)

venkatesh
venkatesh

Reputation: 154

try to check click event in functions

$(document).delegate( '.mydiv', click', function () {

    if(clicked){
          return;
      }
   alert('This is the original event my event!');

});

$(document).delegate( '.mydiv', 'click', function() {
       if(!clicked){
          return;
      }
   alert('Do this and ignore de previous...');

});

Upvotes: 0

Rohan Kumar
Rohan Kumar

Reputation: 40639

Use undelegate function before creating new click function

Docs http://api.jquery.com/undelegate/

Upvotes: 1

Related Questions