views:

25

answers:

2

When I use the following jquery live function

$("a[rel]").live('click', function () {
    e.preventDefault();
    alert('clicked');
});

e.preventDefault(); does not work, because the action behind the a tag is still fired.

How do I prevent an event when I use jQuery.live?

+1  A: 

Don't forget the e inside the function argument list.

$("a[rel]").live('click', function (e) {
    e.preventDefault();
    alert('clicked');
});

You could also try adding

return false;

to the function.

Aaron Hathaway
I think it's the `e`
David Hoerster
+1  A: 

You are missing e argument to the function, try this:

$("a[rel]").live('click', function (e) {
    e.preventDefault();
    alert('clicked');
});
Sarfraz