Sometimes we have to change our website content or text dynamically instantly after page load. At that time, JavaScript comes in the frame to help us.
It is effortless to change text content in our HTML webpage after page load.
Index
There is a simple way to change the text of any element.
We have to use the innerHTML property of our selected element to change the text.
Syntax
document.getElementById(‘id_name’).innerHTML = “new_text”;
<!DOCTYPE html> <html> <title>How to change text on page load</title> <body onload="change_text()"> <p id="demo">Errorsea.com is the best website for web designing</p> <script> function change_text(){ document.getElementById("demo").innerHTML = "Errorsea.com is the best platform to understand basic consepts of website designing"; } </script> </body> </html>
Explanation
Read Also: How to Change Text OnClick Event JavaScript
If we can not set an onload event at <body> tag, we can also use window.onload to set an event for our function in JavaScript.
<!DOCTYPE html> <html> <title>How to change text on page load</title> <body> <p id="demo">Errorsea.com is the best website for web development</p> <script> function change_text(){ document.getElementById("demo").innerHTML = "Errorsea.com is the best platform to understand basic consepts of website development"; } window.onload=change_text; </script> </body> </html>
I am sure you have no dought about adding text using JavaScript after page load.
Enjoy Errorsea 🙂
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
We can redirect any webpage to any other or redirect the whole domain or website…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…