HTML | DOM Title Object
The Title Object in HTML DOM is used to represent the HTML <title> element. The <title> element can be accessed by using getElementByTagName() method.
Syntax:
document.getElementByTagName();
Properties: The title object contains single property text which is used to set or return a text or content of title to the document.
Example 1:
<!DOCTYPE html> < html > < head > < title > DOM Title Object </ title > </ head > < body style = "text-align:center;" > < h1 style = "color:green;" > GeeksforGeeks </ h1 > < h2 >DOM Title Object</ h2 > < p >Welcome to GeeksforGeeks!</ p > < button onclick = "myGeeks()" > Submit </ button > < p id = "sudo" ></ p > <!-- script to display tag name --> < script > function myGeeks() { var g = document.getElementsByTagName("TITLE")[0].text; document.getElementById("sudo").innerHTML = g; } </ script > </ body > </ html > |
Output:
Before Click on the Button :
After Click on the Button:
Example 2: Title Object can be created by using the document.createElement method.
<!DOCTYPE html> < html > < head > </ head > < body style = "text-align:center;" > < h1 style = "color:green;" > GeeksforGeeks </ h1 > < h2 >DOM Title Object</ h2 > < p >Welcome to GeeksforGeeks!</ p > < button onclick = "myGeeks()" > Submit </ button > < p id = "sudo" ></ p > < script > function myGeeks() { var tit_ele = document.createElement("TITLE"); var obj = document.createTextNode("HTML DOM Objects"); tit_ele.appendChild(obj); document.head.appendChild(tit_ele); document.getElementById("sudo").innerHTML = "HTML DOM title Object Created"; } </ script > </ body > </ html > |
Output:
Before Click on the Button:
After Click on the Button:
Supported Browsers: The browser supported by DOM Title Object are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | title Tag
- HTML | DOM title Property
- How to get the title of an HTML page ?
- HTML | title Attribute
- HTML | DOM Title text Property
- How to add icon logo in title bar using HTML ?
- HTML | DOM Object Object
- HTML | DOM BR Object
- HTML| DOM HR Object
- HTML | DOM Nav Object
- HTML | DOM Kbd Object
- HTML | DOM S Object
- HTML | DOM Map Object
- HTML | DOM Div Object
- HTML | DOM Ul Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.