HTML DOM Example>>

The HTML DOM defines an HTML document as a collection of objects.

Objects have properties and methods. Objects can respond to events.


An HTML DOM Example

This coding example shows how the background color of an HTML document can be changed to yellow when a user clicks on it:

<html>

<head>
<script type="text/javascript">
function ChangeColor()
{
document.body.bgColor="yellow"
}
</script>
</head>

<body onclick="ChangeColor()">
Click on this document!
</body>

</html>

Try it yourself


Document Objects

The HTML DOM defines HTML documents as a collection of objects.

The document object is the parent of all the other objects in an HTML document.

The document.body object represents the <body> element of the HTML document.

The document object is the parent of the body object, and the body object is a child of the document object.


Object Properties

HTML document objects can have properties (also called attributes).

The document.body.bgColor property defines the background color of the body object.

The statement document.body.bgColor="yellow" in the example above, sets the background color of the HTML document to yellow.


Object Events

HTML document objects can respond to events.

The onclick="ChangeColor()" attribute of the <body> element in the example above, defines an action to take place when the user clicks on the document.


Functions

The ChangeColor() function in the example above, is a JavaScript function.

The function will be triggered (started) when a user clicks on the HTML document.


Changing Style

The HTML DOM also defines a model for changing the styles of HTML objects.

The coding example below shows how to obtain the same effect as the first example, by changing the style of the body object:

<html>

<head>
<script type="text/javascript">
function ChangeColor()
{
document.body.style.background="yellow"
}
</script>
</head>

<body onclick="ChangeColor()">
Click on this document!
</body>

</html>

<< Back








   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006 All Rights Reserved By CodeDcode.Com