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

136
Views
javascript doesn't display new element to screen

MY html file:

<div class="container">
...    
<button type="button" onclick="displayResult()">Display results</button>
</div>

And I want that after clicking the button, a list would be displayed:

function displayResult() {
    
    const list1 = document.createElement("ul");
    const res = document.getElementsByClassName("container");
    res.appendChild(list1);

    const unordered_list3 = document.createElement("li");
    const text3 = document.createTextNode("3");
    unordered_list3.appendChild(text3);
    list1.appendChild(unordered_list3);

    const unordered_list1 = document.createElement("li");
    const text1 = document.createTextNode("1");
    unordered_list1.appendChild(text1);
    list1.appendChild(unordered_list1);

    const unordered_list2 = document.createElement("li");
    const text2 = document.createTextNode("2");
    unordered_list2.appendChild(text2);
    list1.appendChild(unordered_list2);
}

But when I clicked the button, there's nothing to appear on the screen. Is there something wrong?

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!