0

i used eventListener for add textDecoration, so how can i remove textDecoration with eventListener? it's To-Do list, and i need remove Done task to not-done.

I just wrote this for make the task done:

pTag.addEventListener("click", taskDone);
function taskDone(){
  taskTag.style.textDecoration = "line-through";
}

and wrote this for remove "textDecoration", but doesn't work and didn't remove textDecoration:

    document.removeEventListener("click", remDone);
    function remDone(){
        taskTag.style.textDecoration = "none";
    }

so please tell me what should I do and what is the solution?

Saber
  • 1
  • 4

1 Answers1

0

For DOM objects there is also removeEventListener method, which will remove listener from object. In your case you can call it:

pTag.removeEventListener("click", taskDone);

Answer to actual problem: Adding a check in callback function would be sufficient.

function taskDone(){
  if (isLineThrough) {
       taskTag.style.textDecoration = "none";
       isLineThrough = false;
       return;
  }
  taskTag.style.textDecoration = "line-through";
  isLineThrough = true;
}
Townsheriff
  • 569
  • 6
  • 14
  • actually i used this : document.removeEventListener("click", remDone); function remDone(){ taskTag.style.textDecoration = "none"; } but it doesn't work. i need to remove textDecoration style with click again on "tag" – Saber Apr 06 '19 at 20:34
  • Question then is formulated incorrectly. In this case you could add functionality to your `taskDone` method. – Townsheriff Apr 06 '19 at 20:36