0

I am trying to get all checked chckboxes value of a full page.

the full has all sort of html tags defined.

There is another piece to it which is div which has a parent class of "syllabus". except that class div and any checkboxes inside it will be ignored when the other checkboxes of complete page is checked

I am trying some like this:

$('input[type=checkbox]').each(function () {
    var sThisVal = (this.checked ? $(this).val() : "");
});
singer
  • 23
  • 3

2 Answers2

3

Maybe something like this:

var checkedValues = [];

$('input[type=checkbox]:checked').each(function(){
    checkedValues.push($(this).val());
});

console.log(checkedValues);

Or (using .map() and .get())

var checkedValues = $("input[type=checkbox]:checked").map(function() {
    return $(this).val();
}).get();

console.log(checkedValues);

More info

Mehdi Dehghani
  • 10,970
  • 6
  • 59
  • 64
-1

Here you go with a solution

var sThisVal = [];
$('input[type=checkbox]').each(function () {
  sThisVal.push((this.checked ? $(this).val() : ""));
});

console.log(sThisVal);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" checked value="1">Checkbox 1
<input type="checkbox" value="2">Checkbox 2
<input type="checkbox" checked value="3">Checkbox 3
<input type="checkbox"value="4">Checkbox 4

Hope this will help you.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38