Does something like jQuery.toggle(boolean) exist?

前端 未结 4 1606
情深已故
情深已故 2020-12-08 12:47

I write something similar to the following code a lot. It basically toggles an element based on some condition.

In the following made-up example, the condition is \"

4条回答
  •  鱼传尺愫
    2020-12-08 13:39

    Ok, so I am an idiot and need to RTM before I ask questions.

    jQuery.toggle() allows you to do this out of the box.

    $("button").click(function() {
      var condition = $("#agree").is(":checked") && $("#name").val() != "" );
      $("#mydiv").toggle(condition);
    });
    

提交回复
热议问题