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 bothpreventDefaultandstopPropagation.preventDefaultstops the “default” action on the element,stopPropagationstops 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.