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

195
Views
El valor de entrada no se asigna a un div

Quiero obtener el texto del área de texto (id = getText), y luego asignar su valor al nuevo div que he creado pero el valor no se guarda dentro de ese nuevo div. Lo he intentado muchas veces pero el valor de la entrada no se guarda y no hay cambios cuando hago clic en el botón

 let getText = document.getElementById("getText"); // this is textarea let select = document.getElementById("selectBtn"); //this is button //this is another div let result = document.getElementById("result"); let new_p = document.createElement("div"); //creating element new_p.innerHTML = ""; result.appendChild(new_p); // adding into resut div //getting inner text of the input let value = new_p.innerText; //adding an event listener select.addEventListener("click", function(e) { e.preventDefault(); new_p.innerHTML = value; //it does not works and the value is not saved })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let getText = document.getElementById("getText"); // this is textarea let select = document.getElementById("selectBtn"); //this is button //this is another div let result = document.getElementById("result"); let new_p = document.createElement("div"); //creating element new_p.innerHTML = getText.value; result.appendChild(new_p); // adding into resut div //getting inner text of the input let value = new_p.innerText; //adding an event listener select.addEventListener("click", function(e) { e.preventDefault(); new_p.innerHTML = getText.value; console.log(value) //it does not works and the value is not saved })

Reemplazar new_p.innerHTML = ""; para new_p.innerHTML = getText.value

y dentro del evento de clic,

new_p.innerHTML = getText.value;

En el futuro, intente utilizar editores de código en línea para publicar su código. Dado que podría ser más fácil para cualquier persona ayudarlo, tenga cuidado de eliminar cualquier información personal del código.

Aquí hay un violín con su código https://jsfiddle.net/k8b24n3q/12/

La razón por la que no funcionaba era porque estaba configurando el evento de clic en un valor indefinido.

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!