Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
"getElementByTagName" to add nodes to a list

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'.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!