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

206
Visualizações
Why is jQuery not reading an id of an element?

I have a social media app that returns a list of different posts. Each post has an 'Add Comment' function. This requires the input to have an id field, but I know this needs to be unique, and as there are multiple posts that are dynamically generated I cant just change this.

I decided to concatenate the id with the post id like so:

items.push('<input type="text" class="commentContent" id="commentContent' + val["id"] + '" placeholder="Add A Comment..."></input>');

// Main part
id="commentContent' + val["id"] + '"

This means that each post has the following id attributes:

// Post 1
id="commentContentJTJmY2xpY2tjb250YWluZXIlMmY2Mzc3NzAyNjIzODE1MTQ2MjY="

// Post 2
id="commentContentJTJmY2xpY2tjb250YWluZXIlMmY2Mzc3Njk4NzYyOTgwNTQ4Njg="

And this is what I wanted, the issue is when I am trying the value of the input from post 1 for example. I am trying to access it like this:

$("#" + commentInput).val()

// Console log
customID = "#" + commentInput;
console.log(customID);

// Result
#commentContentJTJmY2xpY2tjb250YWluZXIlMmY2Mzc3NzAyNjIzODE1MTQ2MjY=

But this gives me the following error:

Error: Syntax error, unrecognized expression: #commentContentJTJmY2xpY2tjb250YWluZXIlMmY2Mzc3NzAyNjIzODE1MTQ2MjY=

Even this is the correct ID??

I have tried all the solutions from this question here, but none of them have worked.

Please help!

about 4 years ago · Juan Pablo Isaza
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