JavaScript
HTML
CSS
jQuery
PHP
SQL
WordPress
JavaScript Tutorials

Overview

JavaScript can be used to change data on the page, rewrite the entire page, create popup alerts, write to the console for testing, or print the page.

Writing Content to the Page

The Element innerHTML property can be used to set the HTML content of an element. The HTML element is selected by its id #my_output, and the innerHTML (text inside the paragraph element) is changed to “New content”.

				
					<!-- output to the HTML element -->
<p id="my_output">My content</p>
				
			
				
					document.getElementById('my_output').innerHTML = 'New content';
				
			

Re-Writing the Page

The document.write() method writes directly to an open HTML document. The document.write() method deletes all existing HTML when used on a loaded document.

				
					document.write('Hello World!');
				
			

Creating an Alert Popup in the Browser

The Window alert() method displays an alert popup in the browser with a message and OK button, and is used to display information to the user.

				
					alert('Hello World');
				
			

Writing to the Browser Console for Testing

The console.log() method logs a message to the browser console, which is useful for testing purposes.

				
					console.log('Hello world');
				
			

Printing the Page

The window.print() method opens a print dialog box, which lets the user select from printing options to print the contents of the window.

				
					window.print();
				
			

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

JavaScript
HTML
CSS
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.