Issue
I found some text in webpage using below code
document.body.innerText.indexOf('tested')
document.body.innerText.includes('tested')
after finding the text I want to apply background color to that text.
Solution
Find the reference of the element with your innerText:
let xpath = "//div[text()='tested']";
let element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
Replace div
with whatever type of element you have where the text is present
You can directly change the style once you have the element reference:
element.style.backgroundColor = "red";
Answered By - Aneesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.