OrangePineapple OrangePineapple - 4 months ago 25
Javascript Question

click button does something, then click same button undo it

I'm trying to have a button create a line through a list but if you click it again it'll undo the line-through. I've tried a

but it did not work:

original code:

$("div").on("click", ".doneButt", function(e) {
$(this).parents("li").css("text-decoration", "line-through");

.toggle attempt:

$(".doneButt").toggle(function() {
$(this).parents("li").css("text-decoration", "line-through");
}, function() {
$(this).parents("li").css("text-decoration", "none");


$(".doneButt").click(function() {
.withline {
  text-decoration: line-through
<script src=""></script>

    <input type='button' class='doneButt' value='Click' />

  1. Using .toggleClass()