Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
What is the difference shown in the browser when selecting element using jQuery and JavaScript

I'm using jQuery and JavaScript to select elements. I'm wondering what is the difference between these elements? e.g $(this), this and such. It's kind of confusing.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this is a JavaScript pointer to the caller of the function, sometimes an HTMLElement. this is entirely based on the context in which a function is called, for example, if you create a function in the outermost context of a JS file like so and log this, this is a pointer to the window.

function test() {
  console.log(this); //<-- this = window
}
test();

But a callback from an event on an input will show this as being the input HTMLElement.

let input = document.querySelector("input");
input.addEventListener("change", function(){
  console.log(this); //<-- this = <input>
});

$(this) is a jQuery object constructed with a pointer to this. jQuery objects add a ton of additional functions and shorthand substitutes for standard JavaScript functions. Check the jQuery documentation for all of the different things jQuery can do. You can also construct jQuery objects with a selector, like $("div"), which will contain all <div> elements on the page.

The r.fn.init [...] is just how jQuery objects are printed to the console, versus a standard HTMLElement which is just printed as HTML, e.g. <input type="text"/>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!