Found 2416 Articles for HTML

HTML DOM Heading object

AmitDiwan
Updated on 19-Feb-2021 09:15:01

385 Views

The HTML DOM Heading object is associated with the HTML heading elements ranging from to . Using the heading object we can create and access heading element with the createElement() and getElementById() method respectively.SyntaxFollowing is the syntax for −Creating a Heading object −var p = document.createElement("H1");ExampleLet us look at an example for the Heading object −Live Demo Heading object example Create a h1 element by clicking the below button CREATE    function createH1() {       var h = document.createElement("H1");       var txt = document.createTextNode("H1 element has been created");       h.appendChild(txt); ... Read More

HTML DOM header object

AmitDiwan
Updated on 19-Feb-2021 09:16:25

2K+ Views

The HTML DOM header object is associated with the HTML element that introduced in HTML 5. Using the header object we can create and access element using the createElement() and getElementById() method respectively.SyntaxFollowing is the syntax for −Creating a header object −var p = document.createElement("HEADER");ExampleLet us look at an example for the HTML DOM header object −Live Demo Header object example Create a header element by clicking the below button CREATE    function headerCreate() {       var h = document.createElement("HEADER");       document.body.appendChild(h);       var h2 = document.createElement("H2");     ... Read More

HTML DOM head property

AmitDiwan
Updated on 09-Aug-2019 09:06:49

182 Views

The HTML DOM head property is associated with the HTML element. It is used for returning the element. If there are multiple head elements then it will return the first head element. It is a read-only property.SyntaxFollowing is the syntax for the head property −document.headExampleLet us look at an example for the HTML DOM head property − My title head property example Get this document title by clicking on the below button Get Title    function getTitle() {       var x = document.head.firstElementChild.innerHTML;       document.getElementById("Sample").innerHTML = "The title ... Read More

HTML DOM HashChangeEvent

AmitDiwan
Updated on 19-Feb-2021 09:17:50

95 Views

The HTML DOM HashChangeEvent is a type of interface used for representing those events that fire whenever the # part of the URL has been modified.PropertiesFollowing are the properties for the HashChangeEvent −PropertyDescriptionnewURLTo return the document URL after the hash has been modified.oldURLTo returns the document URL before the hash was changedSyntaxFollowing is the syntax for HashChangeEvent.event.eventPropertyHere, eventProperty is one of the above two properties.ExampleLet us look at an example for the HashChangeEvent.Live Demo HashChangeEvent example Change the hash by clicking the below button CHANGE    function changeHash() {       location.hash = "NEWHASH";   ... Read More

HTML DOM hasFocus() method.

AmitDiwan
Updated on 19-Feb-2021 09:22:45

92 Views

The HTML DOM hasFocus() method is used for knowing if the document or any element inside the document has focus. It does so by returning a boolean value in which true represents the document/element has focus and false represents otherwise.SyntaxFollowing is the syntax for hasFocus() method −document.hasFocus()ExampleLet us look at an example for the hasFocus() method −Live Demo hasFocus() method Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. CHECK ... Read More

HTML DOM hasChildNodes() method

AmitDiwan
Updated on 19-Feb-2021 09:24:11

242 Views

The HTML DOM hasChildNodes() method is used for checking if an element contains child nodes or not. It returns true if the element does contain child nodes otherwise it returns false. It will consider any whitespace as child nodes as whitespace inside the node are basically considered as text nodes.SyntaxFollowing is the syntax for hasChildNodes() method −node.hasChildNodes()ExampleLet us look at an example for the hasChildNodes() method −Live Demo    function checkChild() {       var div = document.getElementById("DIV1").hasChildNodes();       document.getElementById("Sample").innerHTML = div;    } hasChildNodes() method example This is ... Read More

HTML DOM hasAttributes() method

AmitDiwan
Updated on 09-Aug-2019 08:37:34

36 Views

The HTML DOM hasAttributes() method checks if an element has any attributes or not. It returns true if the element does contain any attribute and returns false if it doesn’t. If this method is called on any other node than the element node, the returned value will always be false.SyntaxFollowing is the syntax for hasAttribbutes() method −node.hasAttributes()ExampleLet us look at an example for the hasAttributes() method − hasAttributes() example This paragraph has no attributes CHECK The paragraph above hasAttribute value :    function containsAttr() {       var p = document.getElementsByTagName("P")[0];       document.getElementById("Sample").innerHTML+=p.hasAttributes(); ... Read More

HTML DOM getNamedItem() method

AmitDiwan
Updated on 19-Feb-2021 09:25:22

131 Views

The HTML DOM getNamedItem() method is used for getting the attribute node with a given name as a NamedNodeMap object. To get that specific attribute node we have to call this method only upon the attributes property since the attribute property returns a list from which we can filter a specific attribute using getNamedItem() method.SyntaxFollowing is the syntax for the getNamedItem() method −namednodemap.getNamedItem(nodename)Here, nodename is a mandatory parameter value of type string indicating the name of the node present in the namedNodeMap.ExampleLet us look at an example for the getNamedItem() method −Live Demo getNamedItem() example USERNAME: ... Read More

HTML DOM getElementsByTagName() method

AmitDiwan
Updated on 19-Feb-2021 09:26:36

178 Views

The HTML DOM getElementsByTagName() method is used for getting the collection of all the elements in the document having a given tag name. It returns all the given elements as a NodeList object. You can access any element in the returned object using the index number.The HTMLcollection returned stays sync with the DOM tree without calling the getElementsByTagName() method again and again after removing or adding some elements.SyntaxFollowing is the syntax for the getElementsByTagName() method −element.getElementsByTagName(tagname)Here, tagname is a mandatory parameter value indicating the child elements tagname that we want to get.ExampleLet us look at an example for the getElementsByTagName() ... Read More

HTML DOM getElementsByClassName() method

AmitDiwan
Updated on 09-Aug-2019 08:20:32

262 Views

The HTML DOM getElementsByClassName() method is used for getting the collection of all the elements in the document having a given class name. It returns all the given elements as a NodeList object. You can access any element in the returned object using the index number. This method can be called on any individual element to have its descendant child elements having the given class name.SyntaxFollowing is the syntax for the getElementsByClassName() method −document.getElementsByClassName(classname)Here, the classname is of type string indicating the class name of element you want to access. Multiple class names can also be searched by separating them ... Read More

Advertisements