Getting list of Checked Checkboxes in a Div

Getting list of Checked Checkboxes in a Div

Hi,

            I would like to get a list of the checked CheckBoxes in the div below, when the button is clicked.

 

  1. <div id="ScrollCB" style="height:150;width:200px;overflow:auto">
  2. <input type="checkbox" id="scb1" name="scb1" value="scb1">Milk<br>
  3. <input type="checkbox" id="scb2" name="scb2" value="scb2">Butter<<br>
  4. <input type="checkbox" id="scb3" name="scb3" value="scb3">Cheese<br>
  5. </div>
  6. <input type="button" value="Get Values of Selected" onClick="getSourceValues();">

 

I am trying the following function/method:

 

function getSourceValues() {

  $("#ScrollCB").find(":checkbox").each(function(i) {

            //Attempted some if statements here

                        alert(this.id + " = " + i);

    });

};

 

I tried the various ways of getting the checked using

 

  1. if(this.attr('checked'))

 

and I have not been successful.

 

Thanks a lot guys,

O.O.