Search code examples
javascriptinnerhtmlinnertext

Why this InnerHtml returning same output as innerText


(Beginner) The code below (css excluded) shows same output. But innerHtml should have given the output with html tag right?

HTML

    <div class="sunpath">
        <div class="sun"> SUN </div>
        <div class="planet">
           <div class="stable">
            Planet
           </div>
        </div>
    </div>

Javascript

p = document.querySelector(".sun");
console.log(p.innerHTML);
console.log(p.innerText); 

In console (firefox) both gives the same outputScreenshot


Solution

  • you are right bro: because u r accessing the parent tag:

    if you have do this

       <div class="sun"><p> SUN </p></div>
    

    then tag would be also console