find all selected check boxes using jquery in javascript

To find all selected checkboxes using jQuery, you can use the :checked selector. The :checked selector selects all the checked checkboxes on the page. Here's an example:

index.tsx
// find all selected checkboxes on the page
var selectedCheckboxes = $('input[type=checkbox]:checked');

// loop through the selected checkboxes and do something
selectedCheckboxes.each(function() {
  // do something
});

222 chars
9 lines

In the code above, we're using the $ function to select all checkboxes on the page that have a type of 'checkbox' and are currently checked. We're then storing these elements in a variable called selectedCheckboxes.

We can then loop through the selectedCheckboxes using the each function and do something with each checkbox. For example, we could get the value of the checkbox:

index.tsx
selectedCheckboxes.each(function() {
  var value = $(this).val();
  console.log(value);
});
92 chars
5 lines

In the code above, we're getting the value of each selected checkbox and logging it to the console.

related categories

gistlibby LogSnag