I am using a simple few lines of code to get the labels of checked checkboxes and alert the value. But for some reason the alert shows [object Object] for every checkbox instead of its label. What am I doing wrong?
function validate(){
var interests="";
$('input[type=checkbox]').each(function () {
if (this.checked){
var id=$(this).attr('id');
interests += $("#"+id).next()
}
});
alert(interests);
}
use
.text():Note that you can achive the same result with one line of code:
The one line code jsFiddle