I have a script which is supposed to check a checkbox if the li
is clicked, however this does not happen.
<ul>
<li><input type="checkbox">Tyrannosaurus</li>
<li><input type="checkbox">Tyrannosaurus</li>
<li><input type="checkbox">Tyrannosaurus</li>
<li><input type="checkbox">Tyrannosaurus</li>
<li><input type="checkbox">Tyrannosaurus</li>
<li><input type="checkbox">Tyrannosaurus</li>
</ul>
<script>
$("li").click(function (e) {
var cb = $(this).find(":checkbox")[0];
if (e.target != cb) cb.checked = !cb.checked;
$(this).toggleClass("selected", cb.checked);
});
</script>
Aucun commentaire:
Enregistrer un commentaire