Difference between innerText, innerHTML, and childNodes[].value?

前端 未结 11 1277
别跟我提以往
别跟我提以往 2020-11-22 06:57

What is the difference between innerHTML, innerText and childNodes[].value in JavaScript?

11条回答
  •  忘了有多久
    2020-11-22 07:36

    The only difference between innerText and innerHTML is that innerText insert string as it is into the element, while innerHTML run it as html content.

    const ourstring = 'My name is Satish chandra Gupta.';
    document.getElementById('innertext').innerText = ourstring;
    document.getElementById('innerhtml').innerHTML = ourstring;
    .name{
    color:red;
    }

    Inner text below. It inject string as it is into the element.


    Inner html below. It renders the string into the element and treat as part of html document.

提交回复
热议问题