DEV Community

Vanya
Vanya

Posted on

Answer: Replacing text within a label

You can get the text node by childNodes.

If the text is always at the beginning of the element, you can just change it like this:

document.querySelector('label').childNodes[0].textContent = 'Some word:';
<label>
  Search:
  <input type="text" />
</label>

Top comments (0)