Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda