'preventDefault not working with tab(9) keyCode

I using a keypress event for enter and tab. But for some reason the code only runs with enter. By pressing tab it just does the default tab action and ignores the code. Please help.

onEnterAddWord: function(ev) {
        var kc = ev.which || ev.keyCode;
        if (kc === 13 || kc === 9) {
            ev.preventDefault();
            this.$el.find('.add-word-input input').trigger('blur');
            this.$el.find('.viewbox').trigger('click');
            console.log('check');
        }
    },


Solution 1:[1]

Try keydown instead of keypress

Modifier and non-printing keys does not fire the keypress event.

Solution 2:[2]

How about adding ev.stopImmediatePropagation(); which will prevent other eventListeners to fire?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 schnill
Solution 2 Anton Boritskiy