Treehouse

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!

ydkjs-6.png

Recent Features

  • Chris Coyier’s Favorite CodePen Demos

    Chris Coyer's incredible CodePen is much more than your typical code'n'share site. CodePen features the end result more than the code, provides loads of collaboration tools, and seems to be pushing new features every week. But what...

  • CSS Gradients

    With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements.  CSS gradients are another step in that direction.  Now that CSS gradients are supported in Internet...

  • How to Create a Twitter Card

    One of my favorite social APIs was the Open Graph API adopted by Facebook.  Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to,...

Incredible Demos

  • dwClickable:  Entire Block Clickable Using MooTools 1.2

    I recently received an email from a reader who was really impressed with Block Clickable, a jQuery script that took the link within a list item and made the entire list item clickable. I thought it...

  • Page Visibility API

    One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else?...

  • Create a Clearable TextBox with the Dojo Toolkit

    4/18/2011: ClearTextBox has been updated to hide the clear icon when the value is empty. ClearTextBox has also been updated to use this.connect instead of dojo.connect for code efficiency reasons described by Chris Barber within the comments below.

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)

  4. [...] Lyssna på tangenten Delete Använda MooTools [...]

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

Use Code Editor