user20199678
user20199678

Reputation:

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

Upvotes: 2

Views: 54

Answers (1)

Mikael Tenshio
Mikael Tenshio

Reputation: 150

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

Upvotes: 0

Related Questions