<script> tags can be put between the <head> and </head> tags or between <body> and </body> tags.
How to write, save and run codes:
1. Use any note editor like Notepad, Notepad++ to write the code.
2. Save the page with .html extension and load it in web browser.
1. Create a .js file, and write your JS code in this file using your favorite editor.
<script src="relative_path_to_file/file_name.js"></script> in the end of <body> tag inside HTML file.
Code for Painting the page light blue
The colour of web-page is light blue , but the opening body tag is defined to set background colour to be white.
Learning from the code:
1. Page is known as document for the purpose of scripting in a web page.
2. Properties of the document can be referenced by writing document followed by a dot, followed by the property name. The document has lots of properties.
DISPLAYING THE RESULT ON THE WEBPAGE.
Learning from the code:
1. The following line has been added to this code.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”>
This lets the web browser know that user is using XHTML. It doesn’t actually make any difference to the code; it would work just fine without the extra lines.
2. Notice that <p> tag has been given an id using the id attribute.
document.getElementById(‘ResultsP’).innerHTML = ‘Hello World!’;
The code simply means: “Get me the document element with id ResultsP and set the HTML inside that element to Hello World!”
It is important that the code accessing the paragraph is after the paragraph otherwise, the code would be attempting to access a paragraph before it existed in the page and would throw an error.
- HTTP status codes | Informational Responses
- HTTP status codes | Successful Responses
- How To Troubleshoot Common HTTP Error Codes ?
- Understanding Rainbow Table Attack
- HTML Course | Understanding and Building Project Structure
- PHP | Basic Syntax
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Aanisha Mishra