ccampbell / gator

Event delegation in Javascript
http://craig.is/riding/gators
492 stars 46 forks source link

how do you prevent propagation or default? #2

Closed trailsandtribulations closed 11 years ago

trailsandtribulations commented 11 years ago

since the method only has one arg, how do you e.stopPropagation() or e.preventDefault()?

the classic example is an click trigger on an anchor where you do not want the href to be followed

ccampbell commented 11 years ago

Check the documentation on http://craig.is/riding/gators. You can call it directly:

Gator(document).on('click', 'a', function(e) {
    e.preventDefault();
    _doSomething(this);
});

or you can return false:

Gator(document).on('click', 'a', function(e) {
    _doSomething(this);
    return false;
});