Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda