Skip to content

Instantly share code, notes, and snippets.

@rayinla
Last active December 9, 2017 15:48
Show Gist options
  • Save rayinla/c3bdb2db2b2ccc82593473062ca71ede to your computer and use it in GitHub Desktop.
Save rayinla/c3bdb2db2b2ccc82593473062ca71ede to your computer and use it in GitHub Desktop.
$(document).ready(function(){
//It is important to notice that 'button' is a DOM object with various methods
$('button').on('click', function(){
//We must preserve the button's context
var that = this;
bluezy();
function bluezy(){
//We're saying, "I want to do fun things with <<that>> button object,
//not <<this>> window object you keep giving me
$(that).css("background-color", "blue");
console.log(this); // >> Window
console.log(that);// >> <button>
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment