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

174
Views
¿Por qué todas mis notas nuevas no heredan la función de botón?

Tengo el siguiente código JavaScript que se activa una vez que se carga DOM:

 const add_note = () => { // Creates a new note and its props const new_note = document.createElement("div"); const new_input = document.createElement("input"); const new_form = document.createElement("form"); const new_ol = document.createElement("ol"); const new_button = document.createElement("button"); //Populates the new note with inputs and checkboxes for (let i = 0; i < 5; i++) { let new_li = document.createElement("li"); let new_checkbox = document.createElement("input"); new_checkbox.setAttribute("type", "checkbox"); let new_li_input = document.createElement("input"); new_li_input.classList.add("li_input"); new_ol.appendChild(new_li); new_li.appendChild(new_checkbox); new_li.appendChild(new_li_input); } //New note's settings new_note.setAttribute("id", "note"); new_note.classList.add("note"); new_note.appendChild(new_input); new_input.classList.add("note_input"); new_input.setAttribute("placeholder", "Note's title"); new_note.appendChild(new_form); new_form.appendChild(new_ol); new_ol.setAttribute("id", "ol_id"); new_note.appendChild(new_button); new_button.classList.add("more_items"); new_button.setAttribute("id", "more_items"); //Inserts the new note and button const note_block = document.getElementById("notes"); note_block.appendChild(new_note); const button = document.getElementById("more_items"); button.addEventListener("click", add_more_items); button.innerHTML = "+"; };

Sin embargo, una vez que se crean las notas, solo el botón de la primera nota hereda sus funciones como se ve en la siguiente imagen: Código cargado

He intentado todo lo que puedo, pero no pude resolverlo. De todos modos gracias de antemano.

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

0

Las identificaciones son únicas en html, no puede tener varios elementos con la misma identificación

Elimina estas líneas, conviértelas en clases o distínguelas de alguna manera:

 new_note.setAttribute("id", "note"); ... new_ol.setAttribute("id", "ol_id"); ... new_button.setAttribute("id", "more_items");

Y simplemente consulte el botón con la variable:

 const note_block = document.getElementById("notes"); note_block.appendChild(new_note); new_button.addEventListener("click", add_more_items); new_button.innerHTML = "+";

Incluso podría mover estas dos últimas líneas al resto de su código antes de agregar el bloque de notas.

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!