Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!