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

293
Visualizações
Why does my function return undefined, especially the .split()parts?

So in essence I get the value of input, then try to divide into into different tags via the comma with this

     var noteTags = document.getElementsByClassName("noteTag").value;
          Tag = noteTags.split(",");

But in console, the split(",") is undefined Edit: Sorry I forgot to mention that the noteTag element is input, does this change how the code works in any way?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

There are two issues,

  1. getElementsByClassName returns an array-like collection of elements (a NodeList).
  2. And instead of value it should be innerText.

Try like below

 var noteTags = document.getElementsByClassName("noteTag")[0].innerText;
      Tag = noteTags.split(",");
over 4 years ago · Santiago Trujillo Relatório

0

You are using the split() method on an array. You are also trying to access the value property, whereby you should probably use innerText.

over 4 years ago · Santiago Trujillo Relatório

0

You can use querySelector then you dont need using a key[0] to select the element.

const noteTags = document.querySelector("#noteTag");
console.log(noteTags)
Tag = noteTags.innerHTML.split(",");
console.log(Tag)
<div id="noteTag">en,jp,fr</div>

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