Does anyone have any idea why my preventDefault code isn't working? return false returns fine, but it is my understanding that's not really the 'proper' way?
if ($('.signup').length == 0) {
$('.star').on('click',function(e){
e.preventDefault();
var starElement = $(this);
var resourceId = starElement.parents('li').data('id');
updateFavoritesSpan( starElement, starElement.hasClass('starred') );
starElement.toggleClass('starred');
starElement.parents('li').toggleClass('fvtd');
});
// voting
$('.voting').on('click .up', function(e){
e.preventDefault();
sendVote($(this), 1);
});
$('.voting').on('click', '.down', function(e){
e.preventDefault();
sendVote($(this), -1);
});
}
return false;
does both preventDefault
and stopPropagation
.
preventDefault
stops the "default" action on the element, stopPropagation
stops the event from bubbling up to the parent elements.
My guess is that there is an event on the parent that is still getting triggered when you only do preventDefault
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With