OrangePineapple OrangePineapple - 1 year ago 65
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");

Answer Source

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

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

  1. Using .toggleClass()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download