Skip to content

Instantly share code, notes, and snippets.

@texel
Created December 2, 2013 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texel/7761337 to your computer and use it in GitHub Desktop.
Save texel/7761337 to your computer and use it in GitHub Desktop.
// 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