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

160
Views
La propiedad de estilo dentro de una clase en JavaScript no se actualiza
let taskList = document.getElementById("taskList"); const newItem = new Item("some value"); taskList.append(newItem.item) const updateTaskList = () => { taskList.innerHTML = ""; taskItems = JSON.parse(localStorage.getItem("tasks")); const div = document.createElement("div"); div.innerHTML = taskItems; taskItems = div.querySelectorAll("li"); taskItems.forEach((task) => { taskList.append(new Item("some value").item); }) } const updateLocal = () => { taskList = document.getElementById("taskList"); localStorage.setItem("tasks", JSON.stringify(taskList.innerHTML)); } class Item { constructor(name){ const div = document.createElement("div"); div.innerHTML = name; this.item = div; this.item.addEventListener("click", () => this.changeStyle()); } changeStyle(){ this.item.style.textDecoration = "line-through"; updateLocal(); } } document.addEventListener("DOMContentLoaded", () => { updateTaskList(); })

El estilo se actualiza en el DOM, pero después de volver a cargar la página, el estilo desaparece en lugar de almacenarse localmente. ¿Cuál es el problema aquí?

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

0

Resulta que estaba creando un nuevo elemento de la Clase y no actualizando el estilo. Todo lo que tenía que hacer era pasar los estilos del almacenamiento local a la clase y actualizar los estilos para el nuevo elemento.

 class Item { constructor(name, styles){ const div = document.createElement("div"); div.innerHTML = name; if(styles) div.styles.textDecoration = styles.textDecoration; this.item = div; this.item.addEventListener("click", () => this.changeStyle()); } changeStyle(){ this.item.style.textDecoration = "line-through"; updateLocal(); }

}

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!