Wednesday, 15 January 2014

javascript - adding item to attribute with checkbox -



javascript - adding item to attribute with checkbox -

i have got list of div predefined data-groups. add together data-groups item called "my" jquery means of check sign in checkbox (and remove uncheck).

<div class="item yellow" data-kpi="one" data-res="9" data-ref="3" data-groups='["all", "numbers", "red", "square"]'><input type="checkbox" name="add" value="my" /></div> <div class="item yellow" data-kpi="two" data-res="9" data-ref="3" data-groups='["all", "numbers", "green", "circel"]'><input type="checkbox" name="add" value="my" /></div>

try this. see fiddle demo , watch console

$("input[type=checkbox]").click(function() { if($(this).is(":checked")){ $(this).parent().data("groups").push("my"); console.log($(this).parent().data("groups")) } else{ $(this).parent().data("groups").pop(); console.log($(this).parent().data("groups")) } });

demo

javascript jquery html5

No comments:

Post a Comment