Content deleted Content added
No edit summary Tags: Reverted references removed Visual edit Mobile edit Mobile web edit |
No edit summary |
||
(32 intermediate revisions by 26 users not shown) | |||
Line 1:
{{Short description|Coding interactive or animated websites}}
DHTML allows scripting languages to change variables in a web page's definition language, which in turn affects the look and function of otherwise "static" HTML page content, after the page has been fully loaded and during the viewing process. Thus the dynamic characteristic of DHTML is the way it functions while a page is viewed, not in its ability to generate a unique page with each page load.▼
{{how-to|date=January 2025}}
{{Html series}}
'''Dynamic HTML''', or '''DHTML''', is a term which was used by some browser vendors to describe the combination of [[HTML]], [[Style sheet (web development)|style sheet]]s and [[Dynamic web page#Client-side scripting|client-side scripts]] ([[JavaScript]], [[VBScript]], or any other supported scripts) that enabled the creation of interactive and animated documents.<ref>{{Cite web|title=Document Object Model FAQ|url=https://www.w3.org/DOM/faq.html#DHTML-DOM|access-date=2022-02-16|website=W3C |date=October 22, 2003}}</ref><ref>{{cite web|url=http://www.w3.org/Style/#dynamic|title=Web Style Sheets|website=W3C|access-date=7 April 2018 |date=22 July 1999}}</ref> The application of DHTML was introduced by [[Microsoft]] with the release of [[Internet Explorer 4]] in 1997.<ref>{{Cite web |date=2020-07-19 |title=DHTML {{!}} A Quick Glance of DHTML with Components, Features, Need |url=https://www.educba.com/dhtml/ |access-date=2022-10-13 |website=EDUCBA |language=en-US |first=Priya |last=Pedamkar}}</ref>{{Unreliable source?|date=November 2022}}
By contrast, a dynamic web page is a broader concept, covering any web page generated differently for each user, load occurrence, or specific variable values. This includes pages created by client-side scripting, and ones created by server-side scripting (such as PHP, Python, JSP or ASP.NET) where the web server generates content before sending it to the client.▼
▲DHTML (Dynamic HTML) allows scripting languages, such as JavaScript, to
DHTML is differentiated from Ajax by the fact that a DHTML page is still request/reload-based. With DHTML, there may not be any interaction between the client and server after the page is loaded; all processing happens in JavaScript on the client side. By contrast, an Ajax page uses features of DHTML to initiate a request (or 'subrequest') to the server to perform additional actions. For example, if there are multiple tabs on a page, pure DHTML approach would load the contents of all tabs and then dynamically display only the one that is active, while AJAX could load each tab only when it is really needed.▼
▲By contrast, a [[dynamic web page]] is a broader concept, covering any web page generated differently for each user, load occurrence, or specific variable values. This includes pages created by client-side scripting
▲DHTML is
== Uses ==
DHTML allows authors to add effects to their pages that are otherwise difficult to achieve, by changing the [[Document Object Model]] (DOM) and page style. The combination of HTML, CSS, and JavaScript offers ways to:
* Animate text and images in their document.
Line 16 ⟶ 21:
* Include rollover buttons or drop-down menus.
A less common use is to create browser-based action games. Although a number of games were created using DHTML during the late 1990s and early 2000s,<ref>{{
The term "DHTML" has fallen out of use in recent years as it was associated with practices and conventions that tended to not work well between various web browsers.<ref>{{
DHTML support with extensive DOM access was introduced with [[Internet Explorer 4.0]]. Although there was a basic dynamic system with [[Netscape Navigator|Netscape Navigator 4.0]], not all HTML elements were represented in the DOM. When DHTML-style techniques became widespread, varying degrees of support among web browsers for the technologies involved made them difficult to develop and [[debug]]. Development became easier when [[Internet Explorer 5|Internet Explorer 5.0+]], [[Firefox|Mozilla Firefox]] 2.0+, and [[Opera (web browser)|Opera]] 7.0+ adopted a shared [[Document Object Model|DOM]] inherited from [[ECMAScript]].
== Structure of a web page ==
Line 28 ⟶ 33:
Typically a web page using DHTML is set up in the following way:
<syntaxhighlight lang="
<!DOCTYPE html>
<html lang="en">
Line 56 ⟶ 61:
The following code illustrates an often-used function. An additional part of a web page will only be displayed if the user requests it.
<syntaxhighlight lang="
<!DOCTYPE html>
<html>
Line 89 ⟶ 94:
let displayElement = document.getElementById("toggle-me");
let textElement = document.getElementById("showhide")
textElement.addEventListener("click", function (
changeDisplayState(displayElement, textElement);
});
Line 101 ⟶ 106:
==Document Object Model==
{{main|Document Object Model}}
DHTML is not a technology in and of itself; rather, it
The DOM API is the foundation of DHTML, providing a structured interface that allows access and manipulation of virtually anything in the document. The HTML elements in the document are available as a hierarchical [[tree (data structure)|tree]] of individual objects, making it possible to examine and modify an element and its attributes by reading and setting properties and by calling methods. The text between elements is also available through DOM properties and methods.
Line 115 ⟶ 120:
Inline styles are CSS style assignments that have been applied to an element using the style attribute. You can examine and set these styles by retrieving the style object for an individual element. For example, to highlight the text in a heading when the user moves the mouse pointer over it, you can use the style object to enlarge the font and change its color, as shown in the following simple example.
<syntaxhighlight lang="
<!DOCTYPE html>
<html lang="en">
Line 145 ⟶ 150:
}
document.getElementById("clickable-link").addEventListener("click", function (
showMe();
});
Line 162 ⟶ 167:
== External links ==
{{Sister project|project=wikibooks|text=JavaScript/DHTML}}
* [http://www.quirksmode.org/ QuirksMode], a comprehensive site with test examples and instructions on how to write DHTML code
* [http://www.yourhtmlsource.com/javascript/dhtmlexplained.html Introductory DHTML Tutorial]
|