Hello, friends today in this post we will talk about two Javascript methods that are innerText and innerHTML, and later in this, we will also teach you how to use these methods properly to get the values of any elements.


Also attaching a video tutorial in the Hindi language for a better understanding



innerHTML vs innerText


<!DOCTYPE html> <html> <body> <h1 style="color:red;">innerHTML vs innerText</h1> <button onclick="GetData()">click to run</button> <h3>Demo data will taken from here </h3> <div id="demo_data"><h1>this is an h1 tag</h1><br> <img loading="lazy" src="cat.jpg" height="auto" width="30%"/> <button>Hello plz subscribe</button> </div> <br><br> <hr> <h3>Result will be shown here! </h3> <p id="result"></p> <script> function GetData(){ var data = document.getElementById("demo_data").innerHTML; document.getElementById("result").innerHTML=data; } </script> </body> </html>
One thought on “Javascript innerText vs innerHTML”

Leave a Reply

Your email address will not be published.