Create a Nav Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Nav


You can create a <nav> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">create a NAV element containing a link</button>

<p id="myP"></p>

function myFunction() {//w  w  w  . ja  v  a 2  s. c  om
    var x = document.createElement("NAV");

    var anchorElmnt = document.createElement("A");
    anchorElmnt .setAttribute("href", "/html");
    var txt1 = document.createTextNode("HTML");
    anchorElmnt .appendChild(txt1);



Related Tutorials