The code below correctly changes the text inside of an HTML element by rewriting the entire line of text. This is accomplished using textContent
but innerHTML
can also do this.
document.querySelectorAll(".box")[0].textContent = 'The number of dollars in my bank account is $1';
body {
margin: 0;
padding: 0;
}
.box {
padding: 10px;
font-size: 2rem;
color: white;
font-family: sans-serif;
background-color: blue;
}
<div class="box">The number of dollars in my bank account is ?</div>
However is there a way to change just a portion of the text without having to rewrite the entire line? This probably isn't correct but something like .innerHTML[5, 10] that would change just those specifically targeted characters.
Put simply when Javascript is used to change text or tags inside of an element does it always rewrite the entire section? This might not be visible to the user but is that what always happens behind the scene? Thanks so much!