ShahePars
ShahePars

Reputation: 135

how to show/hide metabox, if click on the Specified category

How to display or Hide a Specified < div id="specified-div"></ div> , when click on the < input type="checkbox" value="9" name="post_category[]" id="in-category-9" checked="checked" >

i need to show #specified-div , when input is checked, and hide #specified-div , when input is not checked .

if it can helps, i use word-press and needs to hide/show meta-box when click on the categories input checkbox?

Upvotes: 0

Views: 490

Answers (1)

Try this, it will use the .prop("checked") to see if the checkbox is either checked or not

$('#in-category-9').on("change", function() {
  if ($(this).prop("checked") == true) {
    $("#specified-div").show()
  } else {
    $("#specified-div").hide()
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="specified-div">HIDE OR SHOW</div>
<input type="checkbox" value="9" name="post_category[]" id="in-category-9" checked="checked">

Upvotes: 1

Related Questions