-2

How to change the value inside a class tag in HTML?

class="headerLogo">BHURTEL<

I want to change "BHURTEL" using user input string using prompt method. I tried this:

let name = prompt("Input your name:");     
document.getElementsByClassName('headerLogo').innerHTML = name;

but it didn't work! is there a way to do it? Or it's not possible?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • You should always check the [docs](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName) first; as the plural s implies, `getElementsByClassName()` returns an array-like collection of elements. –  Sep 21 '20 at 21:52

2 Answers2

-1

use querySelector:

document.querySelector('headerLogo').textContent = name;
olkivan
  • 89
  • 1
  • 3
-1

here is the correct way to get the element

document.querySelector(".headerLogo").innerHTML = 'name'
tarek salem
  • 540
  • 1
  • 6
  • 20