L
L
Legioner9112015-10-19 11:08:20
JavaScript
Legioner911, 2015-10-19 11:08:20

How to implement a checkbox status check and perform an action?

Hello.

The question has probably come up many times. But I couldn't find a good example.

It is necessary that when the radio button for example with (id="one1") is selected, the block with the class for example (class="main-block") is hidden. And when not selected, respectively, it is not hidden.

I hope for a competent answer from a specialist.

Sincerely!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene Tatarinov, 2015-10-19
@Legioner911

$("#one1").on("click", function() {
  if ($("#one1").prop("checked"))
  {
    $(".main-block").css("display", "none");
  }
  else
  {
    $(".main-block").css("display", "block");
  }
});

Example

S
Sergey Zhukov, 2015-10-19
@Adobe

if($('#one1').prop('checked')) $('.main-block').hide();

M
Mikhail Chirsky, 2015-10-19
Chirskiy @chirskiy_mixail

In my opinion, this is more concise, and everywhere in the examples on JQ, just such an example is given:

if($('#one').is(':checked')) {
  $('.main-block').hide();
}
else {
  $('.main-block').show();
}

PS Which one works faster I didn’t check it, if anyone checked it, plz, I’m interested)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question