Created
December 2, 2013 23:54
-
-
Save texel/7761337 to your computer and use it in GitHub Desktop.
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
// Observe click events on h1 elements | |
$('h1').on('click', function( event ) { | |
// This is the body of the click handler. | |
// Notice we were passed the click event as a parameter. | |
// From in here, we can access event to get info about it. | |
var h1 = event.currentTarget; | |
// Interestingly, "this" also refers to the item that was clicked | |
h1 == this; // would evaluate to true | |
// But h1 is just a bare DOM object. If we wanted to call | |
// jQuery methods on it, we need to extend it. | |
// We can do that inline... | |
$(h1).siblings('a').hide(); | |
// Or we can store the extended element in a variable so we | |
// don't need to keep calling $() to extend it... | |
var $h1 = $(h1); | |
$h1.siblings('a').hide(); | |
$h1.css({color: 'blue'}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment