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

224
Views
Change the text of the radio button dynamically

I have a scenario of having a series of radio buttons with a name of the payment method. I need to change that text on load of the page. For Example.

<label class="radio-inline">
  <div class="iradio_square-blue">
    <input type="radio" name="paymentmethod" value="Paypal">
    <ins></ins>
  </div>
  Paypal India
</label>

In the above code sample I need to change the "Paypal India" to "Paypal Global" via javascript We do not have id to the radio button only way to target is via value of the radio button which in the case above is paypal.

Can anyone help me out here.

Thanks in advance.

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

0

You will need to look at the childNodes

const label = document.querySelector("[name=paymentmethod][value=Paypal]")
  .closest("label");
[...label.childNodes].forEach(node => {
  let text = node.textContent;
  if (text && text.includes("India")) {
    node.textContent = text.replace("India", "Global");
  }
});
<label class="radio-inline">
  <div class="iradio_square-blue">
    <input type="radio" name="paymentmethod" value="Paypal">
    <ins></ins>
  </div>
  Paypal India
</label>

about 4 years ago · Juan Pablo Isaza Report

0

Here for your reference. I think it will be helpful.

document.addEventListener("DOMContentLoaded", function(event) {
  const labels = document.getElementsByClassName('radio-inline');
  if (labels.length) {
    let label = labels[0];
    label.innerHTML = label.innerHTML.replace(/Paypal India/, 'Paypal Global');
  }
});
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!