





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






DHTML is the art of combining HTML, JavaScript, DOM, and CSS.
Before you continue you should have a basic understanding of the following:
If you want to study these subjects first, find the tutorials on our Home Page.
DHTML stands for D ynamic HTML.
DHTML is NOT a language or a web standard.
DHTML is a TERM used to describe the technologies used to make web pages dynamic and interactive.
To most people DHTML means the combination of HTML, JavaScript, DOM, and CSS.
According to the World Wide Web Consortium (W3C): "Dynamic HTML is a term used by some vendors to describe the combination of HTML, style sheets and scripts that allows documents to be animated."
Below is a listing of DHTML technologies.
The W3C HTML 4 standard has rich support for dynamic content:
DHTML is about using these features to create dynamic and interactive web pages.
JavaScript is the scripting standard for HTML.
DHTML is about using JavaScript to control, access and manipulate HTML elements.
You can read more about this in the next chapter of this tutorial.
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. You can read more about this in a later chapter of this tutorial.
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. You can read more about this in a later chapter of this tutorial.
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. You can read more about this in a later chapter of this tutorial.
JavaScript can create dynamic HTML content:
Date: Tue Feb 26 2019 06:02:11 GMT+0530 (India Standard Time)
If you have studied JavaScript, you already know that the statement:
document.write()
can be used to display dynamic content to a web page.
Example
Using JavaScript to display the current date:
The DOM presents HTML as a tree-structure (a node tree), with elements, attributes, and text:
innerHTML How to access and change the innerHTML of an element.
Attribute change How to access an image element and change the "src" attribute.
The HTML DOM is:
The HTML DOM defines the objects and properties of all HTML elements, and the methods (interface) to access them.
In other words:
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
The HTML DOM can be used to change the content of an HTML element:
Old Header
HTML output:
Example explained:
Try it yourself
The HTML DOM can be used to change the attribute of an HTML element:
HTML output:
onclick Turn on the light! How to change an image when the user clicks it.
onmousedown & onmouseup This time the light is on only when the user holds down the mouse button.
onload Displays an alert box when the page has finished loading.
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.
Example
A header changes when the user clicks it:
Click on this text
Try it yourself
You can also add a script in the head section of the page and then call the function from the event handler:
Click on this text
Event Occurs when... onabort a user aborts page loading onblur a user leaves an object onchange a user changes the value of an object onclick a user clicks on an object ondblclick a user double-clicks on an object onfocus a user makes an object active onkeydown a keyboard key is on its way down onkeypress a keyboard key is pressed onkeyup a keyboard key is released onload a page is finished loading onmousedown a user presses a mouse-button onmousemove a cursor moves on an object onmouseover a cursor moves over an object
onmouseout a cursor moves off an object onmouseup a user releases a mouse-button onreset a user resets a form onselect a user selects content on a page onsubmit a user submits a form onunload a user closes a page
For a full overview please refer to the complete DOM Event Object Reference in our HTML DOM tutorial.
JavaScript can be used to change the style of an HTML element:
Change the style of the current element How to change the style of an element using the this object.
Change the style of a specific element How to change the style of an element using getElementById.
(You can find more examples at the bottom of this page)
With HTML 4, JavaScript and the HTML DOM can be used to change the style any HTML element.
To change the style the current HTML element, use the statement:
style. property = new style
or more correctly:
this.style. property = new style
Try it yourself
To change the style of a specific HTML element, use the statement:
document.getElementById( element_id ).style. property = new style
Try it yourself
Mouse Events How to change the color of an element when the cursor moves over it.
Visibility How to make an element invisible. Do you want the element to show or not?