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

84
Views
Change content of all elements having same class using javascript

I have a few text elements on the page associated with the class .currency-text. I want to format the value of these elements with 3 digit comma separate.

I have already created a function named formatText() to format text.

function formatText(x) {
   return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

How do I traverse through the document and format all the text elements which have the class .currency-text. I am new to DOM manipulation and don’t know what is the efficient way to do it.

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

0

From my understanding, you can find all elements associated with that class .currency-text and iterate on that returned list. Something is like:

let elements = $(document).find('.currency-text');
elements.each((e) => { e.innerText = formatText(e.innerText); });
about 4 years ago · Juan Pablo Isaza Report

0

Grab the elements with querySelectorAll and then iterate over them applying the formatted text to each element.

const elements = document.querySelectorAll('.currency-text');

elements.forEach(el => {
  el.textContent = formatText(el.textContent);
});
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!