0

I have three check boxes I want to make mutually exclusive. I have written the following code:

window.jQuery && jQuery(window.parent.document).ready(function() {
$('#id1,#id2,#id3').live('change', function(){
if ($this.prop('checked', true))
$('#id1,#id2,#id3').not(this).prop('checked', false)
})});

I have placed this code at the very bottom of the page. I have checked the solutions offered in: HTML <select> JQuery .change not working

I receive no error messages in console before or after pressing the check boxes, it just doesn't seem to work.

Do I need to create a separate function and attach it to an "onchange" event for the check boxes in the HTML code?

Nimrod Yanai
  • 777
  • 2
  • 8
  • 30

1 Answers1

1

Try this:

$('#id1, #id2, #id3').on('change', function() {
  console.log("Changed one!");
  if ($(this).prop('checked', true)) {
    $('#id1,#id2,#id3').not(this).prop('checked', false);
  }
});

You were missing curly brackets following your if statement, and I changed $this to $(this).

Here's a working fiddle: https://jsfiddle.net/o7wptoca/3/