DOM objects, properties, methods, and events
We walked you through the basics of JavaScript objects and will now get to the essence of client-side JavaScript—programming the DOM.
The Window object
When you are running a webpage in a browser, there are two objects available to you—Window object and Document object.
The Window object gives us access to the properties and methods that can tell us about the status of the window that is used to render the webpage. We already used one such method in every single example: alert()
. Consider the following:
alert("Hello, world");
This is actually short for the following:
window.alert("Hello, world");
Similar useful methods for creating a dialog box are prompt
and confirm
. The former displays a dialog box that prompts the visitor for input; the latter displays a dialog box with a message and an OK and Cancel button. Refer to the next example:
var response = confirm ("Are you sure you want to do this?"); if (response...