{"id":134,"date":"2018-07-26T10:33:02","date_gmt":"2018-07-26T10:33:02","guid":{"rendered":"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=134"},"modified":"2018-08-02T06:44:30","modified_gmt":"2018-08-02T06:44:30","slug":"javascript-and-html-dom","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/chapter\/javascript-and-html-dom\/","title":{"rendered":"JavaScript and HTML DOM"},"content":{"raw":"<div>\r\n\r\n<strong>Document Object Model or DOM<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The DOM is a W3C (World Wide Web Consortium) standard. It defines a standard for accessing documents using a platform and language-neutral interface and to dynamically access and update the content, structure and style of a document.<\/p>\r\n&nbsp;\r\n\r\nThe W3C DOM standard is separated into 3 different parts:\r\n\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0\u00a0\u00a0 Core DOM - standard model for all document types\r\n\r\n2.\u00a0\u00a0\u00a0\u00a0\u00a0 XML DOM - standard model for XML documents\r\n\r\n3.\u00a0\u00a0\u00a0\u00a0\u00a0 HTML DOM - standard model for HTML documents\r\n\r\n&nbsp;\r\n\r\n<strong>The Legacy DOM<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This is the model which was introduced in early versions of JavaScript language. It is well supported by all browsers, but allows access only to certain key portions of documents, such as forms, form elements and images.<\/p>\r\n&nbsp;\r\n\r\n<strong>The W3C DOM<\/strong>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">This document object model allows access and modification of all document content and is standardized by the World Wide Web Consortium (W3C). This model is supported by almost all the modern browsers.<\/p>\r\n&nbsp;\r\n\r\n<strong>JavaScript - Document Object Model or DOM<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The way a document content is accessed and modified is called the Document Object Model, or DOM. DOM is an object-oriented model that describes how all elements in an HTML page are arranged. It is used to locate any object in your HTML page (an unique address). Every web page resides inside a browser window which is considered as Window object. A Document object represents the HTML document that is displayed in that window.The Document object has various properties that refer to other objects which allow access to and modification of document content.<\/p>\r\n&nbsp;\r\n\r\n<strong>DOM - Objects<\/strong>\r\n\r\n&nbsp;\r\n\r\nHere is a simple hierarchy of a few important objects shown in Figure 18.1.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-135 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66.png\" alt=\"\" width=\"653\" height=\"351\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 HTML DOM<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The HTML DOM is a standard object model and programming interface for HTML. DOM defines the HTML elements as <strong>objects<\/strong>, the <strong>properties<\/strong> of all HTML elements, the <strong>methods<\/strong> to access all HTML\u00a0<span style=\"text-align: initial;font-size: 1em\">elements, the <\/span><strong style=\"text-align: initial;font-size: 1em\">events<\/strong><span style=\"text-align: initial;font-size: 1em\"> for all HTML elements. The HTML DOM is a standard for how to get, change, add, or delete HTML elements.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0JavaScript \u2013 HTML DOM Programming Interface<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">The HTML DOM can be accessed with JavaScript and with other programming languages.<\/li>\r\n \t<li style=\"text-align: justify\">In the DOM, all HTML elements are defined as <strong>objects<\/strong>.The programming interface defines the properties and methods of each object.<\/li>\r\n \t<li style=\"text-align: justify\">Methods are <strong style=\"text-align: initial;font-size: 1em\">actions<\/strong><span style=\"text-align: initial;font-size: 1em\"> you can perform on HTML Elements.<\/span><\/li>\r\n \t<li style=\"text-align: justify\">Properties are <strong style=\"text-align: initial;font-size: 1em\">values<\/strong><span style=\"text-align: initial;font-size: 1em\"> of HTML Elements that you can set or change.<\/span><\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 \u00a0 Referencing Objects<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Objects can be referenced using their id or name. It should be unique in the hierarchy. It can be referenced using their numerical position in the hierarchy, by the array index. They can also be referenced using their relation to parent, child, or sibling like parentNode, previousSibling, nextSibling, firstChild, lastChild or the childNodes array.<\/p>\r\n&nbsp;\r\n\r\n<strong>Types of DOM nodes<\/strong>\r\n\r\n<\/div>\r\n<table class=\"aligncenter\" style=\"border-collapse: collapse;width: 67.2727%;height: 42px\" border=\"1\">\r\n<tbody>\r\n<tr style=\"height: 14px\">\r\n<td style=\"width: 10.4242%;height: 14px\">1<\/td>\r\n<td style=\"width: 21.2121%;height: 14px\">Element nodes<\/td>\r\n<td style=\"width: 35.6363%;height: 14px\">HTML tag<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"width: 10.4242%;height: 14px\">2<\/td>\r\n<td style=\"width: 21.2121%;height: 14px\">Text nodes<\/td>\r\n<td style=\"width: 35.6363%;height: 14px\">text in a block element<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px\">\r\n<td style=\"width: 10.4242%;height: 14px\">3<\/td>\r\n<td style=\"width: 21.2121%;height: 14px\">Attribute nodes<\/td>\r\n<td style=\"width: 35.6363%;height: 14px\">attribute\/value pair<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<div>\r\n<p style=\"text-align: justify\">Element nodes can have children and\/or attributes. Text or Attribute nodes are children in an element node. They cannot have children or attributes and not usually shown when drawing the DOM tree<\/p>\r\n&nbsp;\r\n\r\n<strong>Traversing the DOM tree<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe nodes in the DOM tree can be traversed using the relationship like firstChild, lastChild, childNodes, nextSibling, previousSibling and parentNode. The description of these relationships are given in the below Table 18.1.\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><strong>Table 18.1 Relationships among Nodes<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-136 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67.png\" alt=\"\" width=\"560\" height=\"191\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Accessing HTML Elements<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">All HTML elements (objects) are accessed through the document object. A document itself is automatically created. There are several ways to access a specific element, either using paths in the DOM tree or retrieval by tag or retrieval by ID.<\/p>\r\n&nbsp;\r\n\r\n<strong>Methods in document and other DOM objects for accessing descendants<\/strong>\r\n\r\n&nbsp;\r\n\r\nThere are two methods in Document object and other DOM objects for accessing the elements. They are,\r\n\r\ngetElementsByTagName\r\n\r\ngetElementsByName\r\n\r\n&nbsp;\r\n\r\n<strong>Accessing Elements by Paths<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example<\/strong>\r\n\r\n&nbsp;\r\n\r\nfunction\u00a0 execute()\r\n\r\n{\r\n\r\nvar img = document.images[0];\u00a0\u00a0\u00a0\u00a0 img.src=\"lighton.gif\"\r\n\r\nvar inx = document.forms[0].elements[0];\u00a0\u00a0\u00a0 inx.value=\"xx\"\r\n\r\nvar iny = document.forms[\"form1\"].elements[\"y\"];\u00a0\u00a0\u00a0\u00a0\u00a0 iny.value=\"yy\"\r\n\r\n}\r\n\r\n&lt;p&gt;&lt;img src=\"lightoff.gif\" alt=\"light off\" id=\"img1\" \/&gt;&lt;\/p&gt; &lt;form id=\"form1\" method=\"get\" action=\"nosuch\"&gt;&lt;p&gt;\r\n\r\n&lt;input type=\"text\" name=\"x\"\/&gt;\r\n\r\n&lt;input type=\"text\" name=\"y\"\/&gt;\r\n\r\n&lt;input type=\"reset\"\/&gt;&lt;\/p&gt;\r\n\r\n&lt;\/form&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Accessing Elements by Tags<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example<\/strong>\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0function\u00a0 execute()<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">{<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">var spans = document.getElementsByTagName(\"span\");<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">spans[0].style.color=\"red\";<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">spans[1].style.color=\"blue\";<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">S<\/span><span style=\"text-align: initial;font-size: 1em\">pans[1].style.fontVariant=\"small-caps\";<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">}<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt; This &lt;span&gt;example&lt;\/span&gt; is lovely. &lt;\/p&gt; &lt;p&gt; But &lt;span&gt; this one &lt;\/span&gt;is even more! &lt;\/p&gt;<\/span>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0<\/strong>\r\n\r\n<strong>Accessing Elements by ID<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example<\/strong>\r\n\r\n&nbsp;\r\n\r\nfunction execute() {\r\n\r\nvar theDiv = document.getElementById(\"div1\");\r\n\r\nif (theDiv.style.visibility==\"hidden\" )\r\n\r\n{ theDiv.style.visibility=\"visible\" } else { theDiv.style.visibility=\"hidden\" }\r\n\r\n}\r\n\r\n&lt;div id = \"div1\"&gt; This text can be hidden! &lt;\/div&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>HTML DOM - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\nTo change the content ( i.e., the innerHTML) of the &lt;p&gt; element with id = \"demo\u201c.\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\ndocument.getElementById(\"demo\").innerHTML = \"Hello World!\";\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\ngetElementById is a method and innerHTML is a property.\r\n\r\n&nbsp;\r\n\r\n<strong>The \u201cwindow\u201d Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is the highest-level object in the JavaScript browser object hierarchy. It is the default object and is created automatically when a page is loaded. Since it is the default object, we may omit writing window explicitly.<\/p>\r\n&nbsp;\r\n\r\nHence we use the method\r\n\r\ndocument.write(\u201ca test message\u201d)\r\n\r\ninstead of\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">window.document.write(\u201ca test message\u201d);<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">It also includes several properties and methods for us to manipulate the webpage.<\/span>\r\n\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">\u201cwindow\u201d Object - Property<\/strong>\r\n\r\n&nbsp;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">Some of the properties of the window object is listed in Table 18.2.<\/span>\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-137 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68.png\" alt=\"\" width=\"575\" height=\"274\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>\u201cwindow\u201d Object - Method<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the methods of the window object is listed in Table 18.3.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-138 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69.png\" alt=\"\" width=\"567\" height=\"250\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>\u201cwindow\u201d Object - Attribute<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the attributes of the window object is listed in Table 18.4.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-139 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70.png\" alt=\"\" width=\"554\" height=\"437\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Window object example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;script&gt;\r\n\r\nvar w;\r\n\r\nfunction openwindow()\r\n\r\n{\r\n\r\nw = window.open('','', 'width=100,height=100');\r\n\r\nw.focus();\r\n\r\n}\r\n\r\nfunction myFunction()\r\n\r\n{\r\n\r\nw.resizeBy(50, 50);\r\n\r\nw.focus();\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;button onclick=\"openwindow()\"&gt;Create window&lt;\/button&gt; &lt;button onclick=\"myFunction()\"&gt;Resize window&lt;\/button&gt; &lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">This example shows the use of <strong>window<\/strong> object. The example shows the open(), resize() and focus() method of the window object. There are two buttons, \"Create Window\" and \"Resize window\". On clicking these buttons, it invokes the open() method or resize() method. Once the window is resized, in order to gain focus on the window, focus() method is also used with the window object as shown in Figure 18.2<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-140 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71.png\" alt=\"\" width=\"631\" height=\"385\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>The \u201cdocument\u201d Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is one of the important objects in any window or frame. The document object represents a web document or a page in a browser window.<\/p>\r\n&nbsp;\r\n\r\n<strong>\u201cdocument\u201d Object - Property<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the properties of the document object is listed in Table 18.5.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><strong>Table 18.5 \u201cdocument\u201d Object - Property<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-141 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72.png\" alt=\"\" width=\"573\" height=\"214\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>\u201cdocument\u201d Object - Method<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the methods of the document object is listed in Table 18.6.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-142 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73.png\" alt=\"\" width=\"586\" height=\"311\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Document Object Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;script&gt;\r\n\r\ndocument.write(\"Hello World!\");\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;p&gt;Click the button to display the number of script elements in the document.&lt;\/p&gt; &lt;button onclick=\"myFunction()\"&gt;Try it&lt;\/button&gt;\r\n\r\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\nfunction myFunction() {\r\n\r\nvar x = document.scripts.length;\r\n\r\ndocument.getElementById(\"demo\").innerHTML = \"Found \" + x + \" script elements.\";\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">This example demonstrates how document object can be used. The write() method can be used with the document object to display output text \"Hello World!\". On clicking the button, the number of scripts found in the document can be displayed using the property \"length\" of the object as shown in Figure 18.3.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-143 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74.png\" alt=\"\" width=\"580\" height=\"356\" \/><\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;p&gt;Click the button to display the URL of the document.&lt;\/p&gt; &lt;button onclick=\"myFunction()\"&gt;Try it&lt;\/button&gt; &lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\nfunction myFunction()\r\n\r\n{\r\n\r\nvar x = document.URL;\r\n\r\ndocument.getElementById(\"demo\").innerHTML = x;\r\n\r\n}\r\n\r\n&lt;\/script&gt;&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Figure 18.4 displays the URL of the document. The example shows the use of the property \"URL\" used with the document object.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-144 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75.png\" alt=\"\" width=\"591\" height=\"375\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>The \u201chistory\u201d Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Each time you visit a web page and click on the \u201cBack\u201d or \u201cForward\u201d arrow buttons on your browser toolbar, you are accessing the history list. You can also add similar buttons \/ links that allow users to move backward and forward via the information stored in the history object.<\/p>\r\n&nbsp;\r\n\r\n<strong>\u201chistory\u201d Object - Property<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the properties of the history object is listed in Table 18.7.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-145 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76.png\" alt=\"\" width=\"576\" height=\"278\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>\u201chistory\u201d Object - Method<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the methods of the history object is listed in Table 18.8.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-146 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77.png\" alt=\"\" width=\"570\" height=\"237\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>History Object Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;p&gt;Display the number of URLs in the history list:&lt;\/p&gt; &lt;button onclick=\"myFunction()\"&gt;Try it&lt;\/button&gt;\r\n\r\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\nfunction myFunction()\r\n\r\n{\r\n\r\ndocument.getElementById(\"demo\").innerHTML = history.length;\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\nFigure 18.5 shows the property length of the history object. It displays the number of URL's in the history list.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-147 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78.png\" alt=\"\" width=\"586\" height=\"372\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>History Object Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;script&gt;\r\n\r\nfunction goBack()\r\n\r\n{\r\n\r\nwindow.history.go(-2)\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;button onclick=\"goBack()\"&gt;Go 2 pages back&lt;\/button&gt; &lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This example uses the method go() of the \"history\" object. Figure 18.6 displays the button \"Go 2 pages back\". On clicking the button, it calls the function goBack() which navigates two pages back and hence the output shown as the Google home page shown in Figure 18.7.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-148 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79.png\" alt=\"\" width=\"593\" height=\"375\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-149 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80.png\" alt=\"\" width=\"608\" height=\"373\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Anchor Object - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n&lt;p&gt; <strong>&lt;a<\/strong> id=\"myAnchor\"\r\n\r\n&nbsp;\r\n\r\nhref=\"http:\/\/www.example.com:4097\/test.htm#part2\"&gt;Exam ple link <strong>&lt;\/a&gt;<\/strong>&lt;\/p&gt; &lt;p&gt;Click the button to display the port num ber of the link above.&lt;\/p&gt; &lt;button onclick=\"myFunction()\"&gt;Try it&lt;\/button&gt;\r\n\r\n&nbsp;\r\n\r\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\n&nbsp;\r\n\r\nfunction myFunction() {\r\n\r\n&nbsp;\r\n\r\n<strong>var x = document.getElementById(\"myAnchor\").port; <\/strong>document.getElementById(\"demo\").innerHTML = x;\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/ body&gt;\r\n\r\n&lt;\/ html&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This example shows the property \"port\" used with the Anchor object. The property retrieves the port number of the anchor given as link and displays it as shown in Figure 18.8.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-150 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81.png\" alt=\"\" width=\"627\" height=\"391\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 The \u201cform\u201d Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The form object is accessed as a property of the document object. Each form element in a form (text input field, radio buttons), is further defined by other objects. The browser creates a unique \u201cform\u201d object for each form in a document. You can access the form object \u201cform1\u201d using the path document.form1.<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Form Element-Based Objects<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nHTML forms can include eight types of input elements\r\n\r\na.\u00a0 Text fields, Textarea fields\r\n\r\nb.\u00a0 Radio buttons\r\n\r\nc.\u00a0 Check box buttons\r\n\r\nd.\u00a0 Hidden fields\r\n\r\ne.\u00a0 Password fields\r\n\r\nf.\u00a0 Combo box select menu\r\n\r\ng. List select menu\r\n\r\n&nbsp;\r\n\r\n<strong>Working with DOM<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;img border=\"0\" src=\"grapes.jpg\" width=\"48\" height=\"48\"&gt;&lt; br&gt; &lt;img border=\"0\" src=\"flower.jpg\" width=\"107\" height=\"98\"&gt;&lt;br&gt; &lt;img border=\"0\" src=\"fish.jpg\" width=\"107\" height=\"98\"&gt;&lt;br&gt; &lt;p&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt; document.write(\"&lt;hr&gt;&lt;b&gt;This document contains: \"\r\n\r\n+\u00a0 document.images.length + \" images.&lt;\/b&gt;\") &lt;\/script&gt;\r\n\r\n&lt;\/p&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This example demonstrate the property length used with the image object. Figure 18.9 displays the number of images found in the document object.<\/p>\r\n&nbsp;\r\n\r\n<strong>Working with DOM - Output<\/strong>\r\n\r\n<\/div>\r\n<strong><img class=\"size-full wp-image-151 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82.png\" alt=\"\" width=\"630\" height=\"392\" \/><\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module is discussed about HTML DOM object hierarchy and explains about how to access HTML elements using DOM. This module also explores about working with DOM objects using JavaScript.<\/p>\r\n&nbsp;\r\n\r\n<strong>Web Links<\/strong>\r\n<ul>\r\n \t<li><em>www.doc.ic.ac.uk\/~rcheung\/teaching\/2720\/<strong>ppt<\/strong>\/lecture04c.<strong>ppt<\/strong><\/em><\/li>\r\n \t<li><em>www.cs.huji.ac.il\/~dbi\/lectures\/d<strong>html<\/strong>\/d<strong>html<\/strong>.<strong>ppt<\/strong><\/em><\/li>\r\n<\/ul>","rendered":"<div>\n<p><strong>Document Object Model or DOM<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The DOM is a W3C (World Wide Web Consortium) standard. It defines a standard for accessing documents using a platform and language-neutral interface and to dynamically access and update the content, structure and style of a document.<\/p>\n<p>&nbsp;<\/p>\n<p>The W3C DOM standard is separated into 3 different parts:<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 Core DOM &#8211; standard model for all document types<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 XML DOM &#8211; standard model for XML documents<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0 HTML DOM &#8211; standard model for HTML documents<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The Legacy DOM<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This is the model which was introduced in early versions of JavaScript language. It is well supported by all browsers, but allows access only to certain key portions of documents, such as forms, form elements and images.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The W3C DOM<\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify\">This document object model allows access and modification of all document content and is standardized by the World Wide Web Consortium (W3C). This model is supported by almost all the modern browsers.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>JavaScript &#8211; Document Object Model or DOM<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The way a document content is accessed and modified is called the Document Object Model, or DOM. DOM is an object-oriented model that describes how all elements in an HTML page are arranged. It is used to locate any object in your HTML page (an unique address). Every web page resides inside a browser window which is considered as Window object. A Document object represents the HTML document that is displayed in that window.The Document object has various properties that refer to other objects which allow access to and modification of document content.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>DOM &#8211; Objects<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Here is a simple hierarchy of a few important objects shown in Figure 18.1.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-135 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66.png\" alt=\"\" width=\"653\" height=\"351\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66.png 653w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66-300x161.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66-65x35.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66-225x121.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-66-350x188.png 350w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 HTML DOM<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The HTML DOM is a standard object model and programming interface for HTML. DOM defines the HTML elements as <strong>objects<\/strong>, the <strong>properties<\/strong> of all HTML elements, the <strong>methods<\/strong> to access all HTML\u00a0<span style=\"text-align: initial;font-size: 1em\">elements, the <\/span><strong style=\"text-align: initial;font-size: 1em\">events<\/strong><span style=\"text-align: initial;font-size: 1em\"> for all HTML elements. The HTML DOM is a standard for how to get, change, add, or delete HTML elements.<\/span><\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0JavaScript \u2013 HTML DOM Programming Interface<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">The HTML DOM can be accessed with JavaScript and with other programming languages.<\/li>\n<li style=\"text-align: justify\">In the DOM, all HTML elements are defined as <strong>objects<\/strong>.The programming interface defines the properties and methods of each object.<\/li>\n<li style=\"text-align: justify\">Methods are <strong style=\"text-align: initial;font-size: 1em\">actions<\/strong><span style=\"text-align: initial;font-size: 1em\"> you can perform on HTML Elements.<\/span><\/li>\n<li style=\"text-align: justify\">Properties are <strong style=\"text-align: initial;font-size: 1em\">values<\/strong><span style=\"text-align: initial;font-size: 1em\"> of HTML Elements that you can set or change.<\/span><\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 \u00a0 Referencing Objects<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Objects can be referenced using their id or name. It should be unique in the hierarchy. It can be referenced using their numerical position in the hierarchy, by the array index. They can also be referenced using their relation to parent, child, or sibling like parentNode, previousSibling, nextSibling, firstChild, lastChild or the childNodes array.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Types of DOM nodes<\/strong><\/p>\n<\/div>\n<table class=\"aligncenter\" style=\"border-collapse: collapse;width: 67.2727%;height: 42px\">\n<tbody>\n<tr style=\"height: 14px\">\n<td style=\"width: 10.4242%;height: 14px\">1<\/td>\n<td style=\"width: 21.2121%;height: 14px\">Element nodes<\/td>\n<td style=\"width: 35.6363%;height: 14px\">HTML tag<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"width: 10.4242%;height: 14px\">2<\/td>\n<td style=\"width: 21.2121%;height: 14px\">Text nodes<\/td>\n<td style=\"width: 35.6363%;height: 14px\">text in a block element<\/td>\n<\/tr>\n<tr style=\"height: 14px\">\n<td style=\"width: 10.4242%;height: 14px\">3<\/td>\n<td style=\"width: 21.2121%;height: 14px\">Attribute nodes<\/td>\n<td style=\"width: 35.6363%;height: 14px\">attribute\/value pair<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\n<p style=\"text-align: justify\">Element nodes can have children and\/or attributes. Text or Attribute nodes are children in an element node. They cannot have children or attributes and not usually shown when drawing the DOM tree<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Traversing the DOM tree<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The nodes in the DOM tree can be traversed using the relationship like firstChild, lastChild, childNodes, nextSibling, previousSibling and parentNode. The description of these relationships are given in the below Table 18.1.<\/p>\n<\/div>\n<p style=\"text-align: center\"><strong>Table 18.1 Relationships among Nodes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-136 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67.png\" alt=\"\" width=\"560\" height=\"191\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67.png 560w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67-300x102.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67-65x22.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67-225x77.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-67-350x119.png 350w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Accessing HTML Elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">All HTML elements (objects) are accessed through the document object. A document itself is automatically created. There are several ways to access a specific element, either using paths in the DOM tree or retrieval by tag or retrieval by ID.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Methods in document and other DOM objects for accessing descendants<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>There are two methods in Document object and other DOM objects for accessing the elements. They are,<\/p>\n<p>getElementsByTagName<\/p>\n<p>getElementsByName<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Accessing Elements by Paths<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>function\u00a0 execute()<\/p>\n<p>{<\/p>\n<p>var img = document.images[0];\u00a0\u00a0\u00a0\u00a0 img.src=&#8221;lighton.gif&#8221;<\/p>\n<p>var inx = document.forms[0].elements[0];\u00a0\u00a0\u00a0 inx.value=&#8221;xx&#8221;<\/p>\n<p>var iny = document.forms[&#8220;form1&#8221;].elements[&#8220;y&#8221;];\u00a0\u00a0\u00a0\u00a0\u00a0 iny.value=&#8221;yy&#8221;<\/p>\n<p>}<\/p>\n<p>&lt;p&gt;&lt;img src=&#8221;lightoff.gif&#8221; alt=&#8221;light off&#8221; id=&#8221;img1&#8243; \/&gt;&lt;\/p&gt; &lt;form id=&#8221;form1&#8243; method=&#8221;get&#8221; action=&#8221;nosuch&#8221;&gt;&lt;p&gt;<\/p>\n<p>&lt;input type=&#8221;text&#8221; name=&#8221;x&#8221;\/&gt;<\/p>\n<p>&lt;input type=&#8221;text&#8221; name=&#8221;y&#8221;\/&gt;<\/p>\n<p>&lt;input type=&#8221;reset&#8221;\/&gt;&lt;\/p&gt;<\/p>\n<p>&lt;\/form&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Accessing Elements by Tags<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example<\/strong><\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0function\u00a0 execute()<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">{<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">var spans = document.getElementsByTagName(&#8220;span&#8221;);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">spans[0].style.color=&#8221;red&#8221;;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">spans[1].style.color=&#8221;blue&#8221;;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">S<\/span><span style=\"text-align: initial;font-size: 1em\">pans[1].style.fontVariant=&#8221;small-caps&#8221;;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">}<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt; This &lt;span&gt;example&lt;\/span&gt; is lovely. &lt;\/p&gt; &lt;p&gt; But &lt;span&gt; this one &lt;\/span&gt;is even more! &lt;\/p&gt;<\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0<\/strong><\/p>\n<p><strong>Accessing Elements by ID<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>function execute() {<\/p>\n<p>var theDiv = document.getElementById(&#8220;div1&#8243;);<\/p>\n<p>if (theDiv.style.visibility==&#8221;hidden&#8221; )<\/p>\n<p>{ theDiv.style.visibility=&#8221;visible&#8221; } else { theDiv.style.visibility=&#8221;hidden&#8221; }<\/p>\n<p>}<\/p>\n<p>&lt;div id = &#8220;div1&#8221;&gt; This text can be hidden! &lt;\/div&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>HTML DOM &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>To change the content ( i.e., the innerHTML) of the &lt;p&gt; element with id = &#8220;demo\u201c.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>document.getElementById(&#8220;demo&#8221;).innerHTML = &#8220;Hello World!&#8221;;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>getElementById is a method and innerHTML is a property.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The \u201cwindow\u201d Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is the highest-level object in the JavaScript browser object hierarchy. It is the default object and is created automatically when a page is loaded. Since it is the default object, we may omit writing window explicitly.<\/p>\n<p>&nbsp;<\/p>\n<p>Hence we use the method<\/p>\n<p>document.write(\u201ca test message\u201d)<\/p>\n<p>instead of<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">window.document.write(\u201ca test message\u201d);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">It also includes several properties and methods for us to manipulate the webpage.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u201cwindow\u201d Object &#8211; Property<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">Some of the properties of the window object is listed in Table 18.2.<\/span><\/p>\n<\/div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-137 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68.png\" alt=\"\" width=\"575\" height=\"274\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68.png 575w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68-300x143.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68-65x31.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68-225x107.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-68-350x167.png 350w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201cwindow\u201d Object &#8211; Method<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the methods of the window object is listed in Table 18.3.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-138 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69.png\" alt=\"\" width=\"567\" height=\"250\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69.png 567w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69-300x132.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69-225x99.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-69-350x154.png 350w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201cwindow\u201d Object &#8211; Attribute<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the attributes of the window object is listed in Table 18.4.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-139 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70.png\" alt=\"\" width=\"554\" height=\"437\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70.png 554w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70-300x237.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70-65x51.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70-225x177.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-70-350x276.png 350w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Window object example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>var w;<\/p>\n<p>function openwindow()<\/p>\n<p>{<\/p>\n<p>w = window.open(&#8221;,&#8221;, &#8216;width=100,height=100&#8217;);<\/p>\n<p>w.focus();<\/p>\n<p>}<\/p>\n<p>function myFunction()<\/p>\n<p>{<\/p>\n<p>w.resizeBy(50, 50);<\/p>\n<p>w.focus();<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;button onclick=&#8221;openwindow()&#8221;&gt;Create window&lt;\/button&gt; &lt;button onclick=&#8221;myFunction()&#8221;&gt;Resize window&lt;\/button&gt; &lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<\/div>\n<p style=\"text-align: justify\">This example shows the use of <strong>window<\/strong> object. The example shows the open(), resize() and focus() method of the window object. There are two buttons, &#8220;Create Window&#8221; and &#8220;Resize window&#8221;. On clicking these buttons, it invokes the open() method or resize() method. Once the window is resized, in order to gain focus on the window, focus() method is also used with the window object as shown in Figure 18.2<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-140 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71.png\" alt=\"\" width=\"631\" height=\"385\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71.png 631w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71-300x183.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71-225x137.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-71-350x214.png 350w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>The \u201cdocument\u201d Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is one of the important objects in any window or frame. The document object represents a web document or a page in a browser window.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201cdocument\u201d Object &#8211; Property<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the properties of the document object is listed in Table 18.5.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><strong>Table 18.5 \u201cdocument\u201d Object &#8211; Property<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-141 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72.png\" alt=\"\" width=\"573\" height=\"214\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72.png 573w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72-300x112.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72-225x84.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-72-350x131.png 350w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201cdocument\u201d Object &#8211; Method<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the methods of the document object is listed in Table 18.6.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-142 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73.png\" alt=\"\" width=\"586\" height=\"311\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73.png 586w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73-300x159.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73-65x34.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73-225x119.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-73-350x186.png 350w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Document Object Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>document.write(&#8220;Hello World!&#8221;);<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;p&gt;Click the button to display the number of script elements in the document.&lt;\/p&gt; &lt;button onclick=&#8221;myFunction()&#8221;&gt;Try it&lt;\/button&gt;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>function myFunction() {<\/p>\n<p>var x = document.scripts.length;<\/p>\n<p>document.getElementById(&#8220;demo&#8221;).innerHTML = &#8220;Found &#8221; + x + &#8221; script elements.&#8221;;<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span><\/p>\n<\/div>\n<p style=\"text-align: justify\">This example demonstrates how document object can be used. The write() method can be used with the document object to display output text &#8220;Hello World!&#8221;. On clicking the button, the number of scripts found in the document can be displayed using the property &#8220;length&#8221; of the object as shown in Figure 18.3.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-143 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74.png\" alt=\"\" width=\"580\" height=\"356\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74.png 580w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74-300x184.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74-225x138.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-74-350x215.png 350w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;p&gt;Click the button to display the URL of the document.&lt;\/p&gt; &lt;button onclick=&#8221;myFunction()&#8221;&gt;Try it&lt;\/button&gt; &lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>function myFunction()<\/p>\n<p>{<\/p>\n<p>var x = document.URL;<\/p>\n<p>document.getElementById(&#8220;demo&#8221;).innerHTML = x;<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Figure 18.4 displays the URL of the document. The example shows the use of the property &#8220;URL&#8221; used with the document object.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-144 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75.png\" alt=\"\" width=\"591\" height=\"375\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75.png 591w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75-300x190.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75-225x143.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-75-350x222.png 350w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>The \u201chistory\u201d Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Each time you visit a web page and click on the \u201cBack\u201d or \u201cForward\u201d arrow buttons on your browser toolbar, you are accessing the history list. You can also add similar buttons \/ links that allow users to move backward and forward via the information stored in the history object.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201chistory\u201d Object &#8211; Property<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the properties of the history object is listed in Table 18.7.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-145 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76.png\" alt=\"\" width=\"576\" height=\"278\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76.png 576w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76-300x145.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76-65x31.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76-225x109.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-76-350x169.png 350w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u201chistory\u201d Object &#8211; Method<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the methods of the history object is listed in Table 18.8.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-146 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77.png\" alt=\"\" width=\"570\" height=\"237\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77.png 570w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77-300x125.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77-225x94.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-77-350x146.png 350w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>History Object Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;p&gt;Display the number of URLs in the history list:&lt;\/p&gt; &lt;button onclick=&#8221;myFunction()&#8221;&gt;Try it&lt;\/button&gt;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>function myFunction()<\/p>\n<p>{<\/p>\n<p>document.getElementById(&#8220;demo&#8221;).innerHTML = history.length;<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>Figure 18.5 shows the property length of the history object. It displays the number of URL&#8217;s in the history list.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-147 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78.png\" alt=\"\" width=\"586\" height=\"372\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78.png 586w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78-300x190.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78-225x143.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-78-350x222.png 350w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>History Object Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>function goBack()<\/p>\n<p>{<\/p>\n<p>window.history.go(-2)<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;button onclick=&#8221;goBack()&#8221;&gt;Go 2 pages back&lt;\/button&gt; &lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This example uses the method go() of the &#8220;history&#8221; object. Figure 18.6 displays the button &#8220;Go 2 pages back&#8221;. On clicking the button, it calls the function goBack() which navigates two pages back and hence the output shown as the Google home page shown in Figure 18.7.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-148 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79.png\" alt=\"\" width=\"593\" height=\"375\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79.png 593w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79-300x190.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79-225x142.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-79-350x221.png 350w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-149 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80.png\" alt=\"\" width=\"608\" height=\"373\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80.png 608w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80-300x184.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80-225x138.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-80-350x215.png 350w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Anchor Object &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&lt;p&gt; <strong>&lt;a<\/strong> id=&#8221;myAnchor&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>href=&#8221;http:\/\/www.example.com:4097\/test.htm#part2&#8243;&gt;Exam ple link <strong>&lt;\/a&gt;<\/strong>&lt;\/p&gt; &lt;p&gt;Click the button to display the port num ber of the link above.&lt;\/p&gt; &lt;button onclick=&#8221;myFunction()&#8221;&gt;Try it&lt;\/button&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>function myFunction() {<\/p>\n<p>&nbsp;<\/p>\n<p><strong>var x = document.getElementById(&#8220;myAnchor&#8221;).port; <\/strong>document.getElementById(&#8220;demo&#8221;).innerHTML = x;<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/ body&gt;<\/p>\n<p>&lt;\/ html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This example shows the property &#8220;port&#8221; used with the Anchor object. The property retrieves the port number of the anchor given as link and displays it as shown in Figure 18.8.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-150 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81.png\" alt=\"\" width=\"627\" height=\"391\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81.png 627w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81-300x187.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81-225x140.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-81-350x218.png 350w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 The \u201cform\u201d Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The form object is accessed as a property of the document object. Each form element in a form (text input field, radio buttons), is further defined by other objects. The browser creates a unique \u201cform\u201d object for each form in a document. You can access the form object \u201cform1\u201d using the path document.form1.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0Form Element-Based Objects<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>HTML forms can include eight types of input elements<\/p>\n<p>a.\u00a0 Text fields, Textarea fields<\/p>\n<p>b.\u00a0 Radio buttons<\/p>\n<p>c.\u00a0 Check box buttons<\/p>\n<p>d.\u00a0 Hidden fields<\/p>\n<p>e.\u00a0 Password fields<\/p>\n<p>f.\u00a0 Combo box select menu<\/p>\n<p>g. List select menu<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Working with DOM<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;img border=&#8221;0&#8243; src=&#8221;grapes.jpg&#8221; width=&#8221;48&#8243; height=&#8221;48&#8243;&gt;&lt; br&gt; &lt;img border=&#8221;0&#8243; src=&#8221;flower.jpg&#8221; width=&#8221;107&#8243; height=&#8221;98&#8243;&gt;&lt;br&gt; &lt;img border=&#8221;0&#8243; src=&#8221;fish.jpg&#8221; width=&#8221;107&#8243; height=&#8221;98&#8243;&gt;&lt;br&gt; &lt;p&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt; document.write(&#8220;&lt;hr&gt;&lt;b&gt;This document contains: &#8221;<\/p>\n<p>+\u00a0 document.images.length + &#8221; images.&lt;\/b&gt;&#8221;) &lt;\/script&gt;<\/p>\n<p>&lt;\/p&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This example demonstrate the property length used with the image object. Figure 18.9 displays the number of images found in the document object.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Working with DOM &#8211; Output<\/strong><\/p>\n<\/div>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-151 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82.png\" alt=\"\" width=\"630\" height=\"392\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82.png 630w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82-300x187.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82-65x40.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82-225x140.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-82-350x218.png 350w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module is discussed about HTML DOM object hierarchy and explains about how to access HTML elements using DOM. This module also explores about working with DOM objects using JavaScript.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Web Links<\/strong><\/p>\n<ul>\n<li><em>www.doc.ic.ac.uk\/~rcheung\/teaching\/2720\/<strong>ppt<\/strong>\/lecture04c.<strong>ppt<\/strong><\/em><\/li>\n<li><em>www.cs.huji.ac.il\/~dbi\/lectures\/d<strong>html<\/strong>\/d<strong>html<\/strong>.<strong>ppt<\/strong><\/em><\/li>\n<\/ul>\n","protected":false},"author":4,"menu_order":16,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-m-vijayalakshmi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-134","chapter","type-chapter","status-publish","hentry","contributor-dr-m-vijayalakshmi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":6,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/134\/revisions"}],"predecessor-version":[{"id":545,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/134\/revisions\/545"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/134\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapter-type?post=134"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/contributor?post=134"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/license?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}