Difference between ‘$(this)’ and ‘this’ keyword selector when using in jQuery

Hey there,

‘this’ and ‘$(this)’ in jQuery 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.

$(this) Example:

this Example:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">