Hello and I know there are few almost same problems around, but I couldn't find solution with answers given on them, so im first time posting here.
I have simple li and label inside of it
<li class="task">
<input type="checkbox" id="task-1" />
<label for="task-1">Random text></label>
</li>
and my jQuery for triggering "done" class is:
$(".task").click(function (e) {
var cb = $(this).find(":checkbox")[0];
if (e.target != cb) cb.checked = !cb.checked;
$(this).toggleClass("done", cb.checked);
});
this actually works fine when clicked on checkbox or on li background, but doesn't work when clicked on label.
My another jQuery that works when clicked on checkbox and label, but not on background is:
$(".task input").change(function () {
$(this).closest('.task').toggleClass('done', $(this).is(':checked'));
});
How can I create jQuery that will activate event when clicked on checkbox, label, or background of li? Thank you and sorry for any mistakes during post.
Fiddle: http://ift.tt/1O4aVRU
Aucun commentaire:
Enregistrer un commentaire