javascript - Why we use $(this) in jquery -


this question has answer here:

i've been searching why use $(this) in jquery . thought ask on stackoverflow , i'm new jquery , i'm curious know $this.

  <h1>example header</h1>    <script>     $('h1').on('click',function(){       $(this).hide(); //???     });   </script> 

here this refers current dom element on working(on event called, click). ex: in

$('h1').on('click',function(){ 

this refer current dom element h1 invoked event.

enclosing $ makes jquery object.

so $(this) refers jquery h1 object.

so $(this) = $('h1') h1 event triggered event.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -