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

170
Views
How to target tag after a class?
<div class="pre-class">
    <div>100%</div>
</div>

I'm trying to remove the percent (%) on the text inside the div after the class pre-class with textContent.replace("%","") but I just can't target that specific div

(I'm working on a longer website with a lot of divs and I can't add an ID to it because it's from a shortcode.)

I thought I could do something like this:

var textContent = document.getElementsByClassName('gamipress-progress-bar-completed').getElementsByTagName('div'); 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You're basically there. Don't forget that getElementsByClassname returns an array, so simply use [0] to retrieve the element. You'll see it working in the snippet below:

var textContent = document.getElementsByClassName('pre-class')[0].getElementsByTagName('div')[0].innerHTML;

console.log(textContent)
<div class="pre-class">
    <div>100%</div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

let containers = document.getElementsByClassName("pre-class");
for (var i = 0; i<containers.length; i++) {
  let current = containers[i];
  let textNode = current.children[0];
  textNode.innerText = textNode.innerText.replace(/(\d)%/, '$1');
};
<div class="pre-class">
    <div>100%</div>
</div>

Alternatively, you could use element.querySelector() (or querySelectorAll) to find the correct element(s) to replace.

let textNode = document.querySelector(".pre-class > div"); // use querySelectorAll in case there can be multiple matches.
textNode.innerText = textNode.innerText.replace(/(\d)%/, '$1');
<div class="pre-class">
    <div>100%</div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can use querySelector

let div = document.querySelector('div.pre-class > div');
div.innerText = div.innerText.replace('%', '')
<div class="pre-class">
    <div>100%</div>
</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!