Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
I changed textContent of my span element and it seems changed on console.log but it does not change on the screen

This is the function where I add a new Item to my to-do list and I am adding span named "delete" to the end of my item as a button.

function newElement() {
count++;
  var li = document.createElement("li");
  var inputValue = document.getElementById("addNewItem").value;
  var t = document.createElement("Label");
  var checkB=document.createElement("input");
  checkB.setAttribute("type","checkbox");
  checkB.setAttribute("id",count);
  t.setAttribute("for",count);
  t.textContent=inputValue;
  t.appendChild(checkB);
  li.appendChild(t);
  if (inputValue === '') {
    alert("You cannot add an empty element!");
  } else {
    document.getElementById("myList").appendChild(li);
  }
  document.getElementById("addNewItem").value = "";
<!--adding delete button to each new item-->
  var span = document.createElement("SPAN");
  span.className = "close";
  span.textContent="delete";
  console.log(span.textContent);
  li.appendChild(span);

}

Here I tried to change the text of span to "cancel". When I check it by console.log(span.textContent) the text looks changed as cancel but on the screen I still see the span as delete

var list = document.querySelector('ul');
list.addEventListener('click', function(e) {
  if (e.target.tagName === 'LABEL') {
     var li=e.target.parentElement;
     var label=e.target;
     label.style.textDecoration="line-through";
     var span=li.getElementsByTagName("span");
     span.textContent="cancel";
     completedTaskHolder.appendChild(li);
    }

it is still still delete

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda