Is it possible to get the element without firstChild.

Please describe your question in detail.

We are considering rewriting the contents using nodeValue in Javascipt,
It won't be rewritten without firstChild.
Do you have any description without firstChild.

Error message It will not be rewritten unless

firstChild. is attached.

### Corresponding source code
<! DOCTYPE html>
    <meta charset = "UTF-8">
      <script tyoe = "text/javascript">
      let nodelist = document.getElementsByTagName ("strong");
          nodelist.item (0) .nodeValue = "Strong"
          //nodelist.item(0).firstChild.nodeValue = "Strong" // Rewrite

Enter the language name here

Supplemental information (FW/tool version etc.)

chrome latest
Please include more detailed information here.

  • Answer # 1



    Description without firstChild.


    is a requirement for your question, how about using textContent instead of nodeValue?

    nodelist.item (0) .textContent = "Strong";

    Operation check sample: https://codepen.io/jun68ykt/pen/VwwNNVd

    Reference: MDN-textContent

  • Answer # 2


    nodelist [0] .textContent = "Strong";

    ThenodeValuefor the node itself isnull.
    If no text node is specified,nodeValuewill not be text.
    nodelist [0] .firstChildis a text node.