Listen for the Delete Key Using MooTools

By  on  

I saw an interesting ticket hit the MooTools Lighthouse system recently. A user reported that they could not use the following code snippet to listen for the delete key:

var isdel = Event.Keys.delete;

While that generally works, it does not work for the delete key because "delete" is a reserved word. Instead, you must listen for the delete key with this code snippet:

var isdel = Event.Keys['delete'];

Very interesting. As flexible as Moo's language is, you can't get around the reserved words!

Recent Features

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

  • By
    MooTools dwCheckboxes Plugin

    Update / Fix: The checkboxes will no longer toggle when the "mouseup" event doesn't occur on a checkbox. Every morning I wake up to a bunch of emails in my Gmail inbox that I delete without reading. I end up clicking so many damn checkboxes...

  • By
    jQuery Comment Preview

    I released a MooTools comment preview script yesterday and got numerous requests for a jQuery version. Ask and you shall receive! I'll use the exact same CSS and HTML as yesterday. The XHTML The CSS The jQuery JavaScript On the keypress and blur events, we validate and...

Discussion

  1. mootools rules! :)

  2. Thanks for keeping us informed, David!

  3. Hugo

    I saw an interesting ticket hit the MooTools Lighthouse system…

    So did you let them know about your solution? :D
    Or did they already take care of that in the docs?

    (not to sound like a jack*ss, of course, just curious)

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!