-1

I am just working on simple TODO app. And I am trying to create a toogleable strike effect on a text on click. Here is my code.

css

.striked{
    text-decoration: line-through;
}

jQuery

$("ul").on("click","li",()=>{
    $(this).toggleClass("striked");
});

Any line inside the function runs but toogleClass shows no effect. Please help

1 Answers1

1

If you want to use jQuery's this, you need to use function () {}, not () => {}. Arrow functions capture the surrounding this, which is not what you want with jQuery.

$("ul").on("click", "li", function () {
    $(this).toggleClass("striked");
});
Anthony Mills
  • 8,676
  • 4
  • 32
  • 51