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

391
Visualizações
jQuery : eq() vs get()

I'm new to jQuery, and I'm wondering what the difference is between jQuery's get() and eq() functions. I may misunderstand what the get() function does, but I thought it odd that I couldn't call a function on the returned on the returned element in the same line.

//Doesn't work
I.e.  $("h2").get(0).fadeIn("slow");

//Works
$("h2").eq(0).fadeIn("slow");
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

.get() and .eq() both return a single "element" from a jQuery object array, but they return the single element in different forms.

.eq() returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions.

.get() returns an array of raw DOM elements. You may manipulate each of them by accessing its attributes and invoking its functions as you would on a raw DOM element. But it loses its identity as a jQuery-wrapped object, so a jQuery function like .fadeIn won't work.

over 4 years ago · Santiago Trujillo Relatório

0

get() returns a DOM element whereas :eq() and eq() return a jQuery element. Since DOM elements have no method fadeIn() it fails.

http://api.jquery.com/get/

Description: Retrieve the DOM elements matched by the jQuery object.

http://api.jquery.com/eq-selector/

Description: Select the element at index n within the matched set.

over 4 years ago · Santiago Trujillo Relatório

0

get(0)(docs) returns the first DOM element in the set.

eq(0)(docs) returns the first DOM element in the set, wrapped in a jQuery object.

That's why .fadeIn("slow"); doesn't work when you do .get(0). A DOM element doesn't have a fadeIn() method, but a jQuery object does.

over 4 years ago · Santiago Trujillo 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