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

162
Views
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
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!