Skip to content

Instantly share code, notes, and snippets.

@JoanClaret
Created February 19, 2015 11:49
Show Gist options
  • Save JoanClaret/a9bea5b92a576dfe083a to your computer and use it in GitHub Desktop.
Save JoanClaret/a9bea5b92a576dfe083a to your computer and use it in GitHub Desktop.
Simple Javascript encapsulation
var linkcolor = (function(selector, $){
$(selector).click(function(e){
// console.log($(this)); // display target element
// console.log(e); // display event information
// console.log(e.clientX); // display event property value
// console.log(e.target); // display event property value
if ($(this).hasClass('active')){
alert($(this).attr('id'));
}
});
});
linkcolor(".js-link", $);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment