Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading