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

381
Visualizações
Why is jQuery .val() returning nothing?

I am trying to get the value of an input. Here is what my form looks like:

enter image description here

This is the HTML for it:

<label for="userName"></label>
<input type="text" class="form-input plain-text" id="userName" placeholder="Username">

Here is the jQuery to get its value and log it:

$("#loginSubmit").click(function() {
    var userName = $("#userName").val();
    console.log(userName);
});

But when I type in some text and hit the login button that has the id #userName, the console returns this:

enter image description here

Why does this not output dwedwed in the console?

Thanks


Solution found in comments

Debugging: I found I have more than one input with the same ID

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Immediate reasons I can see are:

  • you are attaching an event before the DOM is even loaded or before the element is available in the DOM (if you're loading JS in the head instead of bottom of body for example)
  • multiple element's with the same ID
  • you have a stopPropagation on button elements (or this particular identifier) which is blocking the callback

Other than the above, it's hard to determine what is going on without more code/information.

If its a matter of when you are attaching the listener, try adding $(document).ready() around your event listener.

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