// Code goes here
jQuery(function ($) {
var $checkbox = $(':checkbox');
var $result = $('#result');
var selected = [];
$checkbox.on('change', function () {
var $this = $(this);
var isChecked = $this.is(':checked');
var value = $this.data('value');
console.log(isChecked, value);
if (isChecked) {
selected.push(value);
} else {
selected.splice(
selected.indexOf(value),
1
);
}
setResult();
});
function setResult() {
$result.html(selected.join(', ') || 'Nothing');
}
setResult();
});
<label><input type="checkbox" name="t" value="Газ"/>Газ</label>
<label><input type="checkbox" name="t" value="Вода"/>Вода</label>
<label><input type="checkbox" name="t" value="Канализация"/>Канализация</label>
<div id="res"></div>
var res = $('#res')[0];
$('input[name="t"]').change(function(){
var h = $.trim(res.innerHTML.replace(this.value, '').replace(/\s+/, ' '));
if(this.checked){
h+= ' '+this.value;
}
res.innerHTML = h;
})