$(this)

$(this)

  • this one of the most misunderstood concepts in javascript
  • this (pure javascript) refers to the owner of a function
  • $(this) (jquery) gives you reference to uses jQuery to select the current element

Example of $(this) in use


// Event that makes the <p> element disappear when it is clicked

$('p').click(function(){

  // $(this) refers to the jQuery element, $(p), that
  // the click event was called on

  // Tell the <p> element to hide itself
  $(this).hide();
});

JS Bin on jsbin.com


  • The following is example of how a developer could go using javascript to implement an “active link” effect

JS Bin on jsbin.com