0

I'm just starting out with jQuery, and an assignment is asking me to filter a dog breed database by using checkboxes. I've figured out how to remove a certain breed by checking a box, but can't figure out how to add the breed back by clicking the box again. I'm sure this is super simple, but would someone mind helping me out? I'm going back after this graduate class is over on Tuesday to take another class online that moves a lot slower because this is something that, clearly, does not come naturally to me haha. Thanks in advance.

$("#beagle").on('input',function() {
  if ( $(".checkbox").is(":checked")) {
    $(".beagle").removeClass("hidden");
  } else {
    $(".beagle").addClass("hidden");
  }
});
GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
Kristin C.
  • 21
  • 1
  • 1
    The dupe target shows an example of how to handle event on the input. `$(".checkbox").is` isn't looking at the element that the event triggered from, it's looking at any and all elements that match that selector. – Cerbrus Sep 26 '22 at 14:24
  • ^^ ...and then just returning a flag depending on the state of the **first** of them, as is usually the case with jQuery's asymmetric API (setters update all elements in the jQuery set; getters only get from the first one -- except `text`, which just **had** to be different). – T.J. Crowder Sep 26 '22 at 14:47

0 Answers0