The code below doesn't work in the same behavior. The sequence of click event and calling foo() is different. I want to know why they behave different sequence between call click() and iterate the objects before call click() on each.
<script type="text/javascript">
function foo(obj){
alert(obj.id+" ->"+obj.checked);
}
function clickAll(val){
if (val) {
$(":checkbox").click();
} else {
$(":checkbox").each(function(i,obj){
obj.click();
});
}
}
</script>
</head>
<body>
<input type="checkbox" id="check1" onclick="foo(this)" /> a
<input type="checkbox" id="check2" onclick="foo(this)" /> b
<input type="checkbox" id="check3" onclick="foo(this)" /> c
<input type="button" onclick="clickAll(true)" value="click all" />
<input type="button" onclick="clickAll(false)" value="click all each" />
</body>