HTML and CSS Reference
In-Depth Information
Let's go with the latter and bind to the "u" key being released by binding to the keyup event.
When it is, we'll create a fake data object containing all the information required to create a
new comment and pass it to the displayComment function. That comment will then be
displayed in the UI.
Hit the "u" key a few times and see the comments appear.
$ ( function () {
$ ( document ). keyup ( function ( e ) {
e = e || window . event ;
if ( e . keyCode === 85 ){
displayComment ({
"id" : "comment_1" ,
"comment_post_ID" : 1 ,
"date" : "Tue, 21 Feb 2012 18:33:03 +0000" ,
"comment" : "The realtime Web rocks!" ,
"comment_author" : "Phil Leggetter"
});
}
});
});
Great! We now know that our displayComment function works exactly as we expect it to.
Remember to remove the test function before you go live or you'll really confuse your user
every time they press "u" .
Search WWH ::




Custom Search