HTML | DOM Nav Object
The DOM nav object is used to represent the HTML <nav> element. The<nav> element is accessed by getElementById().
Syntax:
document.getElementById("id")
Where id is assigned to the <nav> tag.
Note: The Nav Object is not supported by Internet Explorer 8 and earlier versions.
Example 1:
<!DOCTYPE html> <html> <head> <title> HTML DOM Nav Object </title> </head> <body> <h1> GeeksforGeeks </h1> <h2>HTML DOM nav Object</h2> <nav id = "nav_object"> <a href="#">Data Structure</a> | <a href="#">Algorithm</a> | <a href="#">Programming Languages</a> </nav> <br> <button onclick = "Geeks()"> Click Here! </button> <p id = "sudo"></p> <script> function Geeks() { var obj = document.getElementById("nav_object").innerHTML; document.getElementById("sudo").innerHTML = obj; } </script> </body> </html> |
Output:
Before click on the button:

After click on the button:

Example 2: Nav Object can be created by using the document.createElement method.
<!DOCTYPE html> <html> <head> <title> HTML DOM nav Object </title> </head> <body> <h1 style = "color:green;" > GeeksForGeeks </h1> <h2>DOM nav Object</h2> <button onclick = "Geeks()"> Click Here! </button> <br><br> <script> function Geeks() { var ele = document.createElement("NAV"); document.body.appendChild(ele); var a = document.createElement("A"); a.setAttribute("href", "/html"); var txt = document.createTextNode("Home"); a.appendChild(txt); ele.appendChild(a); } </script> </body> </html> |
Output:
Before click on the button:

After click on the button:

Recommended Posts:
- HTML | DOM Object Object
- HTML | DOM Pre Object
- HTML | DOM Bdo Object
- HTML | DOM DFN Object
- HTML | DOM Ol Object
- HTML | DOM DT Object
- HTML | DOM Div Object
- HTML | DOM dl Object
- HTML | DOM Map Object
- HTML | DOM li Object
- HTML | DOM Kbd Object
- HTML| DOM Ins Object
- HTML | DOM S Object
- HTML | DOM BR Object
- HTML | DOM DD 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.



