I have a serie of checkboxes and I want to gather the selected one. The checkboxes are in div's and when the div is clicked the checkbox should get checked as well:
var oCheckBox = $($(this).find('.chkSocialMediaItem').get(0));
oCheckBox.attr('checked', !$(oCheckBox).attr('checked'));
This works just fine but KnockoutJS doesn't pick up the change and so doesn't update my counter on the selected items.
I read somewhere you need to trigger the change event. But when I listen to the change event on the checkbox it does actually get triggered.
Any help would be appreciated, Thanks !
Update:
I have found a 'knockout' solution. In my div I did a data-bind off the 'click' and changed the checked value in that function:
<script type="text/html" id="Template">
<div class="item" data-bind="click: DivClicked">
<input type="checkbox" data-bind="checked: IsASelectedItem" class="chkSocialMediaItem"/>
</div>
</script>
function SocialMediaSearchItem() {
this.IsASelectedItem = ko.observable();
this.DivClicked = function () {
this.IsASelectedItem(!this.IsASelectedItem());
};
}
Is this the only solution? I would really like 2 see a Jquery solution as well.