Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 1 characters in body
Source Link
Anthony
  • 37.2k
  • 26
  • 103
  • 167
$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

The event handler .change() will bind to whenever the input changes, so for radios/checkboxes, it binds to whenever they're toggled, so no need to use click().

$("input".radio:checkbox").change(function() { var boxChecked = $(this).is(":checked"); if(boxChecked) { ...do ajax... } }); 

But this is kind of sloppy too, considering you could use the toggle() method instead. Plus, are you wanting to destroy the html when they uncheck? Or is this a one time deal?

$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

The event handler .change() will bind to whenever the input changes, so for radios/checkboxes, it binds to whenever they're toggled, so no need to use click().

$("input:checkbox").change(function() { var boxChecked = $(this).is(":checked"); if(boxChecked) { ...do ajax... } }); 

But this is kind of sloppy too, considering you could use the toggle() method instead. Plus, are you wanting to destroy the html when they uncheck? Or is this a one time deal?

$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

The event handler .change() will bind to whenever the input changes, so for radios/checkboxes, it binds to whenever they're toggled, so no need to use click().

$(".radio:checkbox").change(function() { var boxChecked = $(this).is(":checked"); if(boxChecked) { ...do ajax... } }); 

But this is kind of sloppy too, considering you could use the toggle() method instead. Plus, are you wanting to destroy the html when they uncheck? Or is this a one time deal?

added 524 characters in body
Source Link
Anthony
  • 37.2k
  • 26
  • 103
  • 167
$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

The event handler .change() will bind to whenever the input changes, so for radios/checkboxes, it binds to whenever they're toggled, so no need to use click().

$("input:checkbox").change(function() { var boxChecked = $(this).is(":checked"); if(boxChecked) { ...do ajax... } }); 

But this is kind of sloppy too, considering you could use the toggle() method instead. Plus, are you wanting to destroy the html when they uncheck? Or is this a one time deal?

$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

$("input:checkbox:checked") 

will return all checkboxes that are currently checked.

The event handler .change() will bind to whenever the input changes, so for radios/checkboxes, it binds to whenever they're toggled, so no need to use click().

$("input:checkbox").change(function() { var boxChecked = $(this).is(":checked"); if(boxChecked) { ...do ajax... } }); 

But this is kind of sloppy too, considering you could use the toggle() method instead. Plus, are you wanting to destroy the html when they uncheck? Or is this a one time deal?

Source Link
Anthony
  • 37.2k
  • 26
  • 103
  • 167

$("input:checkbox:checked") 

will return all checkboxes that are currently checked.