I'm trying to get the value of the current checkbox from a group of checkboxes with the same class name as below. However the jquery code seems to not be acting out accordingly. Could anyone help me out with this?
HTML
<input type="checkbox" class="checkbox1" value="test"/><br />
<input type="checkbox" class="checkbox1" value="test2"/> <br />
<input type="checkbox" class="checkbox1" value="test3"/>
JS
$(document).ready(function() {
//set initial state.
$('.checkbox1').click(function() {
if ($(this).is(':checked')) {
console.log($('.checkbox1').val());
}
});
});
Any help would be greatly appreciated!
Thank you.