0

So I have this text

" This is Sam.

Sam is my friend.

Sam is ten years old.

Sam likes football."

You can see Sam is repeated so many times. I want to assign it to a variable so that when I need to I can change the character name. Here is how I write it

var name = "sam"
document.getElementsByClassName("name").innerText= name;
<p> This is <span class="name"></span>.</p>
<p> <span class="name"></span> is my friend</p>
<p> <span class="name"></span> is ten years old.</p>
<p> <span class="name"></span> likes football.</p>
However, it didn't work. I also use document.querySelectorAll("span.name").innerText= name; but still didn't work.

Please help me.

Thank you.

The Fox
  • 1
  • 1

0 Answers0