Il problema che mi trovo a non saper risolvere è questo.
Perché se clicco il div con classe "click-it" la checkbox si flagga ma se clicco la checkbox stessa lei non cambia il suo stato?
Ho scritto questo filetto di esempio:
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prova</title>
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" ></script>
<script language="javascript">
$(document).ready(function()
{
$( ".click-it" ).toggle(function(){$(this).addClass("item-checked"); $(this).find('.check-it').attr('checked', true)},
function(){$(this).removeClass("item-checked"); $(this).find('.check-it').attr('checked', false)} )
});
</script>
<style type="text/css">
<!--
.item-checked {
background-color: #FFD;
}
-->
</style>
</head>
<body>
<div class="click-it" style="border: 1px solid #CCC"><input class="check-it" type="checkbox" name="prova" value="" /></div>
</body>
</html>