HTML + CSS + Javascript
Javascript:
<!DOCTYPE html> <html> <head> </head> <body> <script> window.alert('hello world'); </script> </body> </html>
parent.childIf you want to access the location object under window object, in DOM you use
window.locationYou can extend the dot notation like this
window.document.bodyOften times, we omit the window if we are referencing the current document. So you will see something like this
document.bodyEach object in DOM may contain various informations and methods you can use. For example, the window object contains a method (think of it as commands) called alert(). It opens up an alert window within the current window.
window.alert();Most of the time we omit the window because it is at the top the DOM hierarchy and we assume we are referencing the top object if we don't say otherwise
alert();
Sample file: 01_hello.html
<!DOCTYPE html> <html> <head> <title> The Title of this HTML Page </title> </head> <body> <script> window.alert('hello world'); </script> </body> </html>will open up an alert window with the message hello world.
<!DOCTYPE html> <html> <head> <title> The Title of this HTML Page </title> </head> <body> <script> document.write('Hello document'); </script> </body> </html>If you run the above script, the text "Hello document" will be displayed in the body of the HTML page.
The use of Javascript console is a must. Before asking anyone else why your javascript does not work, make sure you check the console.
On Chrome (Mac):View -> Developer -> JavaScript Console
It can be cryptic at first but it is helpful in