I’m having trouble using the event.preventDefault(); for an ahref on my DOM.
How do you prevent the url from posting a nofollow delete, as specified by the HTML using JQuery?
<td class="trash_can">
<a rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are you sure you want to delete Greek Theater at U.C. Berkeley?" href="/promotions/2/places/46">
<img id="trash_can" src="http://test.dev/images/trash.png?1305741883" alt="Trash">
The following code should subvert the HTML but the HTML posts a delete action, prior to giving a “are you sure” warning. nothing is not working:
$(function(){
$('.trash_can a').click(function(event) {
event.preventDefault();
console.log('Clicked Delete');
});
});
It is possible that instead of just
event.preventDefault(), you need to doreturn falsealso or instead. preventDefault() prevents the default action, but the event still bubbles up, possibly to the next handler, which could be the rails handler that Fredrik pointed out: