I am trying to add a list item to my Ordered list by capturing the list item in javaScript using 'getElementByTagName' but it is giving error:
list.appendChild is not a function
{
let btn = document.getElementById("btn");
let list = document.getElementsByTagName("ol");
btn.onclick = function(){
let node = document.createElement("li").appendChild(document.createTextNode("new item"));
list.appendChild(node);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Website</title>
<script defer src = "js/index.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<ol id="items">
<li class="border">Home</li>
<li>Contact</li>
<li class="border" id="special">About us</li>
</ol>
<button id="btn"> Click me</button><br>
</body>
</html>
Note: The code does not give an error if I capture the 'ol' using getElementbyId but I want to know why I'm getting an error with 'getElementByTagName'.