Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 161955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:18:19+00:00 2026-05-11T11:18:19+00:00

As a jQuery neophyte I am somewhat confused by the different contexts in which

  • 0

As a jQuery neophyte I am somewhat confused by the different contexts in which the this keyword is used. Sometimes it refers to a DOM element e.g. this.id and sometimes it refers to a jQuery object e.g. $(this).val().

Remy Sharp’s blog post is helpful but I would like to know how you would explain the difference to a novice. Is the difference strictly a jQuery issue or common to all Javascript?

Thanks for all the responses so far – great stuff, I will pick an answer tomorrow. Here is another blog post I subsequently came across that was also helpful: What is this? by Mike Alsup.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:18:20+00:00Added an answer on May 11, 2026 at 11:18 am

    Remy Sharp’s post is confusing if you don’t read it carefully, in my opinion. The meaning of this never changes. In the example you gave, there were 2 uses of this. As a DOM element in an event:

    $('a').click(function() {     alert(this.tagName); }); 

    and wrapped as a jQuery object in an event:

    $('a').click(function() {     alert($(this).val()); }); 

    If you read the 2 snippets above very carefully you’ll notice that this never changes meaning. It always refers to the DOM element. The difference comes in how it is used.

    In jQuery, by default, this refers to the DOM element (not a jQuery object) which triggered an event. In the second code snippet above, it is still the same DOM element, only it is wrapped in a jQuery element by wrapping $() around it. As with any argument to the jQuery constructor, passing this into the constructor transforms it into a jQuery object.

    I think the confusion comes in when Remy starts talking about jQuery plugins in the same article as jQuery events. jQuery plugins are something that people rarely write and frequently use. When writing a jQuery plugin, you’re working within the context of the jQuery object prototype. In this case, you’re using the word this to refer to the plugin you’re writing. In normal use-cases, you won’t be writing plugins often so this is a much less common scenario. When not in the scope of the plugin, you can’t use this to refer to the jQuery object.


    In the JavaScript language, the keyword this refers to the current instance of an object in JavaScript. When being used in a JavaScript prototype, it refers to the instance of the prototype. Depending on the browser, when using the non-jquery event model, this also refers to the DOM element. Because some browsers (Internet Explorer) don’t refer to this as the DOM element in an event, it makes working with events difficult. To get around this, jQuery performs some JavaScript magic that always makes this refer to the DOM element which triggered the event. That is (one of the many) reasons to use a JavaScript framework instead of rolling your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jquery waypoints fires a callback, when a object appears into viewport with scrolling. This
jQuery.widget(ui.test,{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } $('#someEleme').test(); Right now,
jQuery(document).ready(function ($) { $('body').keypress(function (e) { alert(e.which); }); }); This will pop up an
Jquery did not carry out!!!I don't know why $(.other-edithion).click(function(){ var city = $(this).closest('#city'); if
jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
JQuery-ui will generate a div with a calendar-div class. Sadly this div is no
jQuery code add new virtual object .add to object .main $(document).ready(function(){ $('.main').on('click', '.add', function
jQuery Mobile Docs says if we wrap form element in div containing data-role=fieldcontain proper
jQuery(document).ready(function($) { $('input[type="text"]').live('focus', function() { if (this.value == 'someValue') { this.select(); } }); });
Jquery offset() does strange things, when called on fixed positioned element. First call of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.