Content deleted Content added
Anton.bersh (talk | contribs) →See also: Remove deleted page |
No edit summary |
||
(44 intermediate revisions by 35 users not shown) | |||
Line 1:
{{Short description|Coding interactive or animated websites}}
{{how-to|date=January 2025}}
{{Html series}}
'''Dynamic HTML''', or '''DHTML''', is a
DHTML (Dynamic HTML) allows scripting languages, such as JavaScript, to
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 20 ⟶ 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>{{cite
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 32 ⟶ 33:
Typically a web page using DHTML is set up in the following way:
<syntaxhighlight lang="
<!DOCTYPE html>
<html lang="en">
function init() {
▲ <script>
▲ var myObj = document.getElementById("navigation");
</script>▼
▲ <!--
▲ Often the code is stored in an external file; this is done
▲ by linking the file that contains the JavaScript.
▲ This is helpful when several pages use the same script:
▲ -->
▲ <script src="myjavascript.js"></script>
▲ </body>
</html>
</syntaxhighlight>
Line 63 ⟶ 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>
if (displayElement.style.display === "none" || displayElement.style.display === "") {
} else
}▼
}
document.getElementById('showhide').addEventListener('click', function (e) {▼
let displayElement =
let textElement =
</script>▼
event.preventDefault();
▲ </body>
changeDisplayState(displayElement, textElement);
</body>
</html>
</syntaxhighlight>
Line 107 ⟶ 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.
The DOM also provides access to user actions such as pressing a key and clicking the mouse. It is possible to intercept and process these and other events by creating [[event handler]] functions and routines. The event handler receives control each time a given event occurs and can carry out any appropriate action, including using the DOM to change the document.
==Dynamic styles==
Line 121 ⟶ 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">
</html>
</syntaxhighlight>
Line 168 ⟶ 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]
|