Reputation: 843
I have an html element like:
<div id="el1">Change only me<div>but not me</div></div>
but I only wanna change the first text and leave the child div as it is
document.getElementById("el1").innerText = "changed!"
<div id="el1">Change only me<div>but not me</div></div>
Upvotes: 4
Views: 6461
Reputation: 28424
Try this:
document.getElementById("el1").childNodes[0].textContent = "changed";
<div id="el1">Change only me<div>but not me</div></div>
Upvotes: 13