- Writing into an HTML element, using
- Writing into the HTML output using
- Writing into an alert box, using
- Writing into the browser console, using
id attribute defines the HTML element. The
innerHTML property defines the HTML content:
Changing the innerHTML property of an HTML element is a common way to display data in HTML.
For testing purposes, it is convenient to use
Using document.write() after an HTML document is loaded, will delete all existing HTML:
The document.write() method should only be used for testing.
You can use an alert box to display data:
You can skip the
window keyword is optional:
For debugging purposes, you can call the
console.log() method in the browser to display data.
You will learn more about debugging in later articles.
The only exception is that you can call the
window.print() method in the browser to print the content of the current window.
Hope you have learned something useful. Thanks for reading the whole story. If you enjoyed our article, don’t forget to share your ideas and follow :)