get the app get the app       get the app       get the app
Difference between $(this) and 'this' in jQuery?


  • : 282
  • : 5
    Previous Next

    this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.

    $(document).ready(function(){
    $('#spnValue').mouseover(function(){
    alert($(this).text());
    });
    });


    In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.

    $(document).ready(function(){
    $('#spnValue').mouseover(function(){
    alert(this.innerText);
    });
    });

    you can suggest other answer in comment box


  • Exam: jQuery Interview





    Recommended Learning for you

    Close(X)
    Subscribe here for free mock test on IAS PCS SSC and other competitive exam. Signup here to get SSC CGL Solution and main exam study material