Docsity

Intoduction to DHTML, Lecture notes of Web Programming and Technologies

Toggle sidebar
bg1
Introduction to DHTML
DHTML is the art of combining HTML, JavaScript, DOM, and CSS.
What you should already know
Before you continue you should have a basic understanding of the following:
•HTML
•JavaScript
•CSS
If you want to study these subjects first, find the tutorials on our Home Page.
DHTML is Not a Language
DHTML stands for Dynamic 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."
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.
You can read more about this in the next chapter of this tutorial.
HTML DOM
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Intoduction to DHTML and more Lecture notes Web Programming and Technologies in PDF only on Docsity!

Introduction to DHTML

DHTML is the art of combining HTML, JavaScript, DOM, and CSS.

What you should already know

Before you continue you should have a basic understanding of the following:

• HTML

• JavaScript

• CSS

If you want to study these subjects first, find the tutorials on our Home Page.

DHTML is Not a Language

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."

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.

You can read more about this in the next chapter of this tutorial.

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. You can read more about this in a later chapter of this tutorial.

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. You can read more about this in a later chapter of this tutorial.

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. You can read more about this in a later chapter of this tutorial.

DHTML JavaScript

JavaScript can create dynamic HTML content:

Date: Tue Feb 26 2019 06:02:11 GMT+0530 (India Standard Time)

JavaScript Alone

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:

DHTML - HTML Document Object Model (DOM)

The DOM presents HTML as a tree-structure (a node tree), with elements, attributes, and text:

Examples

innerHTML How to access and change the innerHTML of an element.

Attribute change How to access an image element and change the "src" attribute.

What is the HTML DOM?

The HTML DOM is:

• A standard object model for HTML

• A standard programming interface for HTML

• Platform- and language-independent

• A W3C standard

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.

Using the HTML DOM to Change an HTML Element

The HTML DOM can be used to change the content of an HTML element:

Old Header

HTML output:

New Header

Example explained:

• The HTML document contains a header with id="header"

• The DOM is used to get the element with id="header"

• A JavaScript is used to change the HTML content (innerHTML)

Try it yourself

Using the HTML DOM to Change an HTML Attribute

The HTML DOM can be used to change the attribute of an HTML element:

HTML output:

Examples

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.

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.

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

HTML 4.0 Event Handlers

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

More About HTML Events

For a full overview please refer to the complete DOM Event Object Reference in our HTML DOM tutorial.

DHTML CSS

JavaScript can be used to change the style of an HTML element:

Examples

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)

JavaScript, DOM, and CSS

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

More examples

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?