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

108
Views
mi función de lista no funciona en javascript

así que escribí este código que crearía una lista y luego le agregaría una entrada al hacer clic. realmente simple pero el problema es que no funciona y no tengo idea de por qué aquí está el código:

 function pushing() { var li = document.createElement("li"); var inputValue = document.getElementById("inp").value; var pushchild = document.createTextNode(inputValue); li.appendChild(pushchild); } sub.addEventListener("click", pushing);

el id inp es un id de entrada. gracias

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Su elemento de lista nunca se agrega a un elemento de lista.

 // Cache the elements, // add the button listener, // & focus on the input const list = document.querySelector('ul'); const input = document.querySelector('#inp'); const sub = document.querySelector('#sub'); sub.addEventListener('click', pushing); input.focus(); function pushing() { const li = document.createElement('li'); const text = document.createTextNode(input.value); li.appendChild(text); // Adding the list item to the list element list.appendChild(li); }
 <input id="inp" /> <button id="sub">Click</button> <ul></ul>

about 4 years ago · Juan Pablo Isaza Report

0

Agregue esto a la última línea de su función. Agregue su elemento li recién creado al ul.

 document.querySelectorAll('ul').appendChild(newCreatedLi);
about 4 years ago · Juan Pablo Isaza Report
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!