JavaScript Output

Using innerHTML

The innerHTML property is used to change the HTML content of an element.

Explanation of Code:

Tutorials dojo strip

The changeContent function changes the content of the <p> element with the ID demo to “Content has been changed!” when the button is clicked.

HTML

Using document.write()

The document.write() method writes directly to the HTML document. It’s typically used for testing purposes and not recommended for production.

Explanation of Code:

The document.write method writes the text “This is written directly to the document.” to the HTML document.

HTML

Using alert()

The alert() method displays a message in an alert box.

Explanation of Code:

The showAlert function displays an alert box with the message “This is an alert box!” when the button is clicked.

HTML

Using console.log()

The console.log() method is used to display output in the browser’s console, which is useful for debugging.

Explanation of Code:

The console.log method logs the message “This message is logged to the console.” to the browser’s console.

HTML

JavaScript Labs

Tutorials dojo strip