I want to replace only the text of a given element and it should be it's own function.
For example, something like this:
<div id="thisDivIsGettingTargeted">
<span>
Edit me!
<i class="fas fa-edit"></i>
</span>
</div>
should be replaced to this:
<div id="thisDivIsGettingTargeted">
<span>
Oh yeah
<i class="fas fa-edit"></i>
</span>
</div>
It's not always the first child, so I can't use firstChild
.
I really don't have any idea, how to achieve this. I have to search for the lowest element and have to change it's text, but in this example, it always finds the i
tag.
That's the function I wrote.
const get_object = element => {
if (!element.hasAttribute("data-liner-stop-search") && element.childElementCount === 1){
return get_object(element.firstElementChild)
}
return element
};
Here's another example:
<span class="text-one-liner">
<span class="name">
Username
<span data-tooltip="A tooltip">
<i class="fas fa-crown"></i>
</span>
</span>
</span>
.text-one-liner
is targeted and "Username" should be changed.