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

114
Views
parseFloat returning NAN even tough I am parsing a number

Problem using parseFloat even though I am parsing a number, but still returing NaN

<div class="tip-custom" id="tip-custom"><input type="number" placeholder="CUSTOM"></div>

const tipCustom = document.querySelector(".tip-custom");
tipCustom.addEventListener("input", tipInputFun);
let tipValue = 0.15;
 function tipInputFun() {
  tipValue = parseFloat(tipCustom.value / 100);
  console.log(tipValue);
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Your querySelector looks for an element that has a class tip-custom.

In your code I see a div with id tip-custom (that is #tip-custom) and your input being inside the div.

You need to fix your selector to properly find the element with your text. You could do something like this

document.querySelector("#tip-custom>input");

Takes the first input, inside an element with id tip-custom.

const tipCustom = document.querySelector("#tip-custom>input");

tipCustom.addEventListener("input", tipInputFun);
let tipValue = 0.15;

function tipInputFun() {
  tipValue = parseFloat(tipCustom.value / 100);
  console.log(tipValue);
}
<div class="tip-custom" id="tip-custom"><input type="number" placeholder="CUSTOM"></div>

about 4 years ago · Juan Pablo Isaza Report

0

tipCustom is the div, not the input, so tipCustom.value is undefined.

about 4 years ago · Juan Pablo Isaza Report

0

Keep it simple and follow the good practices.

let tipValue = 0.15;
function tipInput() {
  tipValue = parseFloat(this.value / 100);
  console.log(tipValue);
}
document.querySelector(".tip-custom > input").addEventListener("input", tipInput);
<div class="tip-custom" id="tip-custom"><input type="number" placeholder="CUSTOM"></div>

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