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

192
Views
How to divide the price by 2 using JS

How to divide the price by 2 using JS? I tried this but it didn't work.

<script>
const a = parseInt(document.getElementById('price_value').textContent)
const b = 2
const result = a / b

document.getElementById('result').innerHTML = result
</script>

<body>
<span class="wcpa_price"><span class="woocommerce-Price-currencySymbol">$</span><span class="price_value">29.00</span></span>
<div id="result"></div>
</body>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

2 things:

  • the script tag must be below the elements. Otherwise, when the script ran, the elements would not have been loaded yet.

  • There is no element with the id price_value. You should be selecting the element with that class instead.

<body>
<span class="wcpa_price"><span class="woocommerce-Price-currencySymbol">$</span><span class="price_value">29.00</span></span>
<div id="result"></div>
<script>
const a = parseInt(document.querySelector('.price_value').textContent)
const b = 2
const result = a / b

document.getElementById('result').innerHTML = result
</script>
</body>

about 4 years ago · Juan Pablo Isaza Report

0

Problem here is that you do not have element with id price value but you have class on it called like that.

Issue is here:

document.getElementById('price_value')

To fix this add id "price_value" on the span element of the price.

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!