DHTML TutorialDHTML stands for Dynamic Hypertext Markup language i.e., Dynamic HTML. Dynamic HTML is not a markup or programming language but it is a term that combines the features of various web development technologies for creating the web pages dynamic and interactive. The DHTML application was introduced by Microsoft with the release of the 4th version of IE (Internet Explorer) in 1997. Components of Dynamic HTMLDHTML consists of the following four components or languages:
HTML 4.0HTML is a client-side markup language, which is a core component of the DHTML. It defines the structure of a web page with various defined basic elements or tags. CSSCSS stands for Cascading Style Sheet, which allows the web users or developers for controlling the style and layout of the HTML elements on the web pages. JavaScriptJavaScript is a scripting language which is done on a client-side. The various browser supports JavaScript technology. DHTML uses the JavaScript technology for accessing, controlling, and manipulating the HTML elements. The statements in JavaScript are the commands which tell the browser for performing an action. DOMDOM is the document object model. It is a w3c standard, which is a standard interface of programming for HTML. It is mainly used for defining the objects and properties of all elements in HTML. Uses of DHTMLFollowing are the uses of DHTML (Dynamic HTML):
Features of DHTMLFollowing are the various characteristics or features of DHTML (Dynamic HTML):
Difference between HTML and DHTMLFollowing table describes the differences between HTML and DHTML:
DHTML JavaScriptJavaScript can be included in HTML pages, which creates the content of the page as dynamic. We can easily type the JavaScript code within the <head> or <body> tag of a HTML page. If we want to add the external source file of JavaScript, we can easily add using the <src> attribute. Following are the various examples, which describes how to use the JavaScript technology with the DHTML: Document.write() MethodThe document.write() method of JavaScript, writes the output to a web page. Example 1: The following example simply uses the document.write() method of JavaScript in the DHTML. In this example, we type the JavaScript code in the <body> tag. Test it NowOutput: JavaScript and HTML eventA JavaScript code can also be executed when some event occurs. Suppose, a user clicks an HTML element on a webpage, and after clicking, the JavaScript function associated with that HTML element is automatically invoked. And, then the statements in the function are performed. Example 1: The following example shows the current date and time with the JavaScript and HTML event (Onclick). In this example, we type the JavaScript code in the <head> tag. Test it NowOutput: Explanation: In the above code, we displayed the current date and time with the help of JavaScript in DHTML. In the body tag, we used the anchor tag, which refers to the page itself. When you click on the link, then the function of JavaScript is called. In the JavaScript function, we use the alert() method in which we type the date() function. The date function shows the date and time in the alert dialog box on the web page. JavaScript and HTML DOMWith version 4 of HTML, JavaScript code can also change the inner content and attributes of the HTML event. Example 1: This example checks the Grade of a student according to the percentage criteria with the JavaScript and HTML DOM. In this example, we type the code of a JavaScript in the <body> tag. Test it NowOutput: Explanation: In the above code, we check the student’s Grade with the help of JavaScript in DHTML. In the JavaScript code, we used the checkGrade() method, which is invoked when we click on the button. In this function, we stored the value in variable p. The value is taken in the input field. When the value is stored, then we convert the value of p into integer and store the conversion value in x, because the value in p is text. After that, we used the if-else-if statement for finding the grade according to the percentage. CSS with JavaScript in DHTMLWith version 4 of HTML, JavaScript code can also change the style such as size, color, and face of an HTML element. Example 1: The following example changes the color of a text. Test it NowOutput: Explanation: In the above code, we changed the color of a text by using the following syntax: The above syntax is used in the JavaScript function, which is performed or called when we clicked on the HTML buttons. The different HTML buttons specify the color of a text. DHTML CSSWe can easily use the CSS with the DHTML page with the help of JavaScript and HTML DOM. With the help of this.style.property=new style statement, we can change the style of the currently used HTML element. Or, we can also update the style of any particular HTML element by document.getElementById(id).style.property = new_style statement. Example 1: The following example uses the DHTML CSS for changing the style of current element: Test it NowOutput: Explanation: In the above code, we used the this.style.color='blue' statement, which shows the color of a text as blue. Example 2: The following example uses the DHTML CSS for changing the style of the HTML element: Test it NowOutput: Explanation: In the above code, we used the var element = document.getElementById('demo').style.color = newColor; statement, which changes the color of a text as green and blue according to the buttons. DHTML EventsAn event is defined as changing the occurrence of an object. It is compulsory to add the events in the DHTML page. Without events, there will be no dynamic content on the HTML page. The event is a term in the HTML, which triggers the actions in the web browsers. Suppose, any user clicks an HTML element, then the JavaScript code associated with that element is executed. Actually, the event handlers catch the events performed by the user and then execute the code. Example of events:
Following table describes the Event Handlers used in the DHTML:
Following are the different examples using the different event handlers, which helps us to understand the concept of DHTML events: Example 1: This example uses the onclick event handler, which is used to change the text after clicking. Test it NowOutput: Example 2: This example uses the onsubmit event handler, which gives an alert after clicking on a submit button. Test it NowOutput: DHTML DOMDHTML DOM stands for Dynamic HTML Document Object Model. It is a w3c standard, which is a standard interface of programming for HTML. It is mainly used for defining the objects and properties of all elements in HTML. It also defines the methods for accessing the HTML elements. Example: The following program helps in understanding the concept of DHTML DOM. This example changes the color of text and displays the text in red colour automatically. Test it NowOutput: Advantages of DHTMLFollowing are the various benefits or the advantages of DHTML (Dynamic HTML):
Disadvantages of DHTMLFollowing are the various disadvantages or limitations of DHTML (Dynamic HTML):
|