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

112
Views
Changing form label (No ID or class) via script

I have a form in one of my apps:

<div class="custom-form-field">
    <label>
        Email
        <span class="required-asterix"></span>
    </label>
    <input name="email" class="email" type="email" placeholder="Work Email" tabindex="0" value="">
</div>

I have the ability to run a custom script in the header or the body of the page, and I would like to change the label from "Email" to "Company email".

Any suggestions? Thanks

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

0

To match an element by its contents you'll need to use XPath.

let emailLabels = document.evaluate( "//div[contains(@class, 'custom-form-field')]/label[contains(., 'Email')]", document, null, XPathResult.ANY_TYPE, null );

let label = emailLabels.iterateNext();

label.innerText = "Company Email";
<div class="custom-form-field">
    <label>
        Email
        <span class="required-asterix"></span>
    </label>
    <input name="email" class="email" type="email" placeholder="Work Email" tabindex="0" value="">
</div>

about 4 years ago · Juan Pablo Isaza Report

0

If you want to use native javascript, can try this:

<div class="custom-form-field"><label>Email<span class="required-asterix"></span></label><input name="email" class="email  " type="email" placeholder="Work Email" tabindex="0" value=""></div>
<script>
  custom_field = document.getElementsByClassName('custom-form-field');
  custom_field[0].children[0].outerText = 'Company Email';
</script>

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!