Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda