How to Display using JavaScript
JavaScript can display data in many ways.
- Writing into an HTML element - innerHTML
- Writing into the HTML output - document.write()
- Writing into an alert box - window.alert()
- Writing into the browser console - console.log()
To access an HTML element,you can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content. For example,
var element = document.getElementById('demo')
element.innerHTML = 'Hello World!';
The document.write() method should only be used for testing.
For debugging purposes, you can use the console.log() method to display data.