DHTML Tutorial
DHTML Tutorial
• DHTML is NOT a language. It is a TERM describing the art of making dynamic and interactive web
pages.
• DHTML combines HTML, JavaScript, DOM, and CSS.
DHTML Introduction
DHTML is the art of combining HTML, JavaScript, DOM, and CSS.
DHTML Technologies
Below is a listing of DHTML technologies.
HTML 4
• The W3C HTML 4 standard has rich support for dynamic content:
• HTML supports JavaScript
• HTML supports the Document Object Model (DOM)
• HTML supports HTML Events
• HTML supports Cascading Style Sheets (CSS)
• DHTML is about using these features to create dynamic and interactive web pages.
JavaScript
JavaScript is the scripting standard for HTML.
DHTML is about using JavaScript to control, access and manipulate HTML elements.
HTML DOM
• The HTML DOM is the W3C standard Document Object Model for HTML.
• The HTML DOM defines a standard set of objects for HTML, and a standard way to access and
manipulate them.
• DHTML is about using the DOM to access and manipulate HTML elements.
HTML Events
• The W3C HTML Event Model is a part of the HTML DOM.
• It defines a standard way to handle HTML events.
• DHTML is about creating web pages that reacts to (user)events.
CSS
CSS is the W3C standard style and layout model for HTML.
CSS allows web developers to control the style and layout of web pages.
HTML 4 allows dynamic changes to CSS.
DHTML is about using JavaScript and DOM to change the style and positioning of HTML elements.
DHTML - JavaScript
JavaScript can create dynamic HTML content.
Date: Mon Jun 01 2009 13:11:38 GMT+0800
JavaScript Alone
If you have studied JavaScript, you know that the statement:
document.write()
You will learn more about JavaScript and the HTML DOM in the next chapter of this tutorial.
JavaScript and HTML Events
A JavaScript can also be executed when an event occurs, like when a user clicks on an HTML element.
To execute code when a user clicks on an element, use the following event attribute:
onclick=JavaScript
You will learn more about JavaScript and HTML Events in a later chapter.
In other words:
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
Example explained:
1. The HTML document contains a header with id="header"
2. The DOM is used to get the element with id="header"
3. A JavaScript is used to change the HTML content (innerHTML)
Example explained:
1. The HTML document loads with an image with id="image"
2. The DOM is used to get the element with id="image"
3. A JavaScript changes the src attribute from smiley.gif to landscape.jpg
Event handlers
An event handler allows you to execute code when an event occurs.
Events are generated by the browser when the user clicks an element, when the page loads, when a form is
submitted, etc.
In the following example, the h1 heading changes when a user clicks on it:
Example
<html>
<body>
<h1 onclick="this.innerHTML='Ooops!'">Click on this text</h1>
</body>
</html>
You can also add a script in the head section of the page and then call the function from the event handler:
Example
<html>
<head>
<script type="text/javascript">
function changetext(id)
{
id.innerHTML="Ooops!";
}
</script>
</head>
<body>
<h1 onclick="changetext(this)">Click on this text</h1>
</body>
</html>
DHTML - CSS
JavaScript and the HTML DOM can be used to change the style of any HTML element.
Change Style of Current HTML Element
To change the style of the current HTML element, use the statement:
this.style.property=new styleExample<html>
<body>
<h1 id="header" onclick="this.style.color='red'">Click Me!</h1>
</body></html>
DHTML Summary
• DHTML is about combining HTML, JavaScript, DOM, and CSS.
• DHTML is a Term
In this tutorial you have learned that DHTML is only a term used to describe the different combinations of
HTML, JavaScript, DOM, and CSS that can be used to create more dynamic web pages.
JavaScript
JavaScript is the standard scripting language for the Internet.
Everyone serious about web development should have a full understanding of JavaScript.
Dynamic CSS
There is no such thing as dynamic CSS.
However, with JavaScript and the HTML DOM you can dynamically change the CSS style of any HTML
element.
At W3Schools you can study the following server side scripting tutorials:
• PHP tutorial
• ASP tutorial
• DotNET tutorial