I’m making a basic task list using localStorage & Contenteditable and when I hit enter (in chrome) the browser adds a new line. I want to prevent this default behaviour and submit the task. The jQuery blur removes the focus but only after adding a new line still.
I tried using,
return false
e.preventDefault();
e.stopPropagagtion();
But none of them worked, is there anyway to prevent this?
$('.taskContent').keyup(function(e) {
if(e.keyCode == 13) {
$('.task').removeClass('editing');
$('.task').children('a').fadeTo('medium', 0.5, function() {
localStorage.setItem('tasksData', tasks.innerHTML);
});
$('.taskContent').blur();
}
});
I’ve run into this problem before, and I think the issue is that the event fires on keydown not keyup for return/enter/tab and other “special function” keys.
Try changing it to