spyderman4g63
spyderman4g63

Reputation: 4309

How to add a YUI keyup listener

How do I add a YUI keyup listener? This is very simple with jQuery but I don't understand how to do it with YUI. There appears to be a YAHOO.util.KeyListener but it looks like that only listens for specific keys. I also tried to use YAHOO.util.Event.addListener but I couldn't get it to work with keyup. I'm not sure if addListener can use a keyup event since the YUI documentation is god awful.

Is there a way to create a listener for a key up even using YUI (aka the satanic framework)?

Upvotes: 1

Views: 2124

Answers (1)

Luke
Luke

Reputation: 2581

YUI 2.x:

YAHOO.util.Event.on('elId', 'keyup', function (e) {
    /* Your code here */
});

YUI 3.x:

Y.one('#elId').on('keyup', function (e) {
    /* Your code here */
});

There is no magic involved in hooking up the events. If you're having trouble, it may be related to the keyCodes or charCodes you're looking to react to. There are browser quirks with the key events. More detail or a code reduction would be helpful to get you up and running. There's also the #yui IRC channel on freenode.

Upvotes: 1

Related Questions