| 1. |
Explain The Difference Between “this” And “$(this)” In Jquery? |
|
Answer» “this” REFERS to the current ELEMENT in the scope. “this” will be used in TRADITIONAL JAVASCRIPT and “$(“this”)” if used then we will get the benefits of Jquery METHODS. For example: Using “$(this)” - $(document).ready(function(){ $('#mycontrolid').change(function(){ alert($(this).text()); }); }); Using “this” - $(document).ready(function(){ $('# mycontrolid'').change(function(){ alert(this.innerText); }); }); “this” refers to the current element in the scope. “this” will be used in traditional javascript and “$(“this”)” if used then we will get the benefits of Jquery methods. For example: Using “$(this)” - $(document).ready(function(){ $('#mycontrolid').change(function(){ alert($(this).text()); }); }); Using “this” - $(document).ready(function(){ $('# mycontrolid'').change(function(){ alert(this.innerText); }); }); |
|