Javascript DOM HTML Nav Object

Introduction

The Nav object represents an HTML <nav> element.

We can access a <nav> element via document.getElementById():

var x = document.getElementById("myNav");

Click the button to get the HTML content of the nav element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<nav id="myNav">
  <a href="#">HTML</a> |
  <a href="#">CSS</a>
</nav>/*ww w.j  ava 2 s.  c o  m*/
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myNav").innerHTML;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related