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

456
Views
Grab the value from a span (not the text) using javascript

I am attempting to grab the value of a span attribute but am only successful so far in grabbing the text (which I don't need in this case).

// I want the value to return "10"


myValue = document.querySelector(".count-total").getElementByID("data-multiply")
console.log(myValue)
<div class="count-total">
  <span data-multiply="10">20 Doses</span>
</div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Target the span with querySelector, and then get the multiply value from the dataset.

const span = document.querySelector('.count-total span');
console.log(span.dataset);
const val = span.dataset.multiply;
console.log(val);
<div class="count-total">
  <span data-multiply="10">20 Doses</span>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

Use the dataset attribute: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

const node = document.querySelector(".count-total span[data-multiply]")
console.info(node.dataset.multiply)
<div class="count-total">
  <span data-multiply="10">20 Doses</span>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

.getElementByID("data-multiply") is neither syntactically correct nor will it get the data attribute

it is spelled getElementById but is used when an element has an ID

You need to use the querySelector with the complete path and use the dataset property

// I want the value to return "10"
const myValue = document.querySelector(".count-total span").dataset.multiply;
console.log(myValue)
<div class="count-total">
  <span data-multiply="10">20 Doses</span>
</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!