JS, How to change only parent element

I have something like that :

<h3 id="plop">I want to change this text <span id="trololo">bla bla bla</span> </h3>

Generaly, I use js to change text on my html elements :

document.getElementById("plop").innerHTML = "I change the text";

But do something like this remove my span element on title. Then, is it possible to change only the text on h3 ?

I know, i can do something like that:

document.getElementById("plop").innerHTML = "I change the text <span id=\"trololo\">bla bla bla</span>";

But is not my goal.

Read more here: https://stackoverflow.com/questions/64891962/js-how-to-change-only-parent-element

Content Attribution

This content was originally published by KasaiJo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: