Skip to content Skip to sidebar Skip to footer

Specific Keyboard Event

I'm using Vue and I have the Quill editor inside a div (which is why I'm using the deprecated DOMSubtreeModified), and I want to fire an event to send an API request to save the co

Solution 1:

This can be done using simple JavaScript:

var myElem = document.querySelector('#myElem');
myElem.addEventListener('keydown', (event) => {
    if (event.key === "Backspace") {
        //Do Something
    }
    else {
        //Do Something (Or Not)
    } 
});

Or even jQuery:

$('#myElem').on('keydown', (event) => {
    if (event.key === "Backspace") {
        //Do Something
    }
});

myElem doesn't even have to be a text box, it could be a <div> with no contenteditable properties! The event.key is the newer standard than event.keyCode or event.which. That is, according to Mozilla Docs.

Hope that helps...

Edit: This link is still under development but it shows how to register the Arrow Keys and even Shift: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Example


Post a Comment for "Specific Keyboard Event"