How should I code to: select checkbox -> table hide in 1sec -> console.log(hide) -> select checkbox again -> show the table -> console.log(show);?

Viewed 15

Unfortunately it doesn't work. (Rather, it works, but not in a proper way.)

HTML:

  <div>
       <label id="myButton"> Show/Hide
            <input type="checkbox"  name="tableShowOrHide" value="C">
       </label>
  </div>

SCRIPT:

$('#myButton').click(function () {
    $('table').finish().show(1000, function () {
        console.log("We can see the table.");
    });
    $('#myButton').click(function () {
        $('table').finish().hide(1000, function () {
            console.log("Was there a table?!");
        });
    });
});

Thanks a lot in advance!

1 Answers

Your problem is that you have two functions that will run when you click your button. To solve this, combine them in a way like this:

$("#myButton").click(function() {
if ($("p").is(":visible")) {
    $('table').finish().hide(1000);
    console.log("Was there a table?!");
} else {
    $('table').finish().show(1000);
    console.log("We can see the table.");
}

})

If it doesn't work, can you please post the full HTML as well?

Related