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

190
Views
Trouble finding in the page source the related name/id to replace text using getElement(s)By.innerHTML

I'm trying to replace some text on a webpage using a tampermonkey script but I'm having trouble identifying the proper element. I have gotten this to work in the past but it's fairly hit-or-miss.

For the source below I was thinking I should use document.getElementsByClassName("product-return-message__label product-return-message__label--pdp product-return-message__label--pdp-large").innerHTML = "blah blah blah" based on the closest class name but it's not working.

In general I am having difficulty identifying which name/id belongs to the text I want to replace when looking at the source of a webpage. If you could please identify the getElement(s) and name/id I should use based on the source below I would be grateful! Thanks!

partial source: ... <div class="product-return-message product-return-message--pdp product-return-message--pdp-large" data-test="message"><svg aria-hidden="true" role="img" viewBox="0 0 100 100" class="product-return-message__icon"></svg><div class="product-return-message__content product-return-message__content--pdp product-return-message__content--pdp-large" data-test="message-content"><div aria-level="2" class="product-return-message__label product-return-message__label--pdp product-return-message__label--pdp-large" data-test="message-label" role="heading">TEXT I WANT TO REPLACE</div> ...

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

0

how about using document.querySelector with attribute CSS selector ?

const element = document.querySelector("div[data-test='message-label']");

if(element) {
  element.innerHTML = "found!";
}
<div class="product-return-message product-return-message--pdp product-return-message--pdp-large" data-test="message">
<div class="product-return-message__content product-return-message__content--pdp product-return-message__content--pdp-large" data-test="message-content"><div aria-level="2" class="product-return-message__label product-return-message__label--pdp product-return-message__label--pdp-large" data-test="message-label" role="heading">TEXT I WANT TO REPLACE</div>
<svg aria-hidden="true" role="img" viewBox="0 0 100 100" class="product-return-message__icon"></svg>

about 4 years ago · Juan Pablo Isaza Report

0

QuerySelector would be help. Like @Tareq you can search by div[data-test='message-label'] or in you case: document.querySelector('div > div > div').innerHTML = Hello World. The more pleasant way of these two variants is the one by tareq.

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!