I'm trying to work on some js code to:
- Create a nav menu
- Create a header, nav, ul, and li element(s) w/in js
- Be automatically invoked
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<script src="js1.js">
cHeader();
</script>
</head>
<body>
</body>
</html>
Here is the js:
function cHeader(){
var header = document.createElement("header");
var body = document.getElementById("body");
body.appendChild(header);
var ul = document.createElement("ul");
header.appendChild(ul);
var li = document.createElement("li");
ul.appendChild(li);
var liNode = document.createTextNode("Home");
li.appendChild(liNode);
}
When I try to call the function by either <body onLoad="cHeader()"> or with <script>cHeader()</script> in the html, my console in Chrome returns with:
Uncaught ReferenceError: cHeader is not defined index.html:19
(anonymous function)
Although, even when I try inline script tags, the code won't do anything.