Last active
August 29, 2015 14:03
-
-
Save lishiyo/95798b62450c74364b59 to your computer and use it in GitHub Desktop.
Blog - jQuery events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//calls handler once and sets up subsequent action | |
$( "button" ).one( "click", firstClick ); | |
function firstClick() { | |
$('p').text( "You just clicked this for the first time!" ); | |
// Set up the new handler for subsequent clicks with $(this).click | |
// (omit if no further click responses are needed) | |
$( this ).click( function(){ | |
$('p').text( "You\'ve clicked this before!" ); | |
}); | |
} | |
// You can also .one() to bind several events - each will be allowed to be called once | |
$( "input[id]" ).one( "focus mouseover keydown", firstEvent); | |
function firstEvent( eventObject ) { | |
console.log( "A " + eventObject.type + " event occurred for the first time on the input with id " + this.id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment