Here is the jsfiddle http://jsfiddle.net/6mk7m/9/
I have found out on stackoverflow that I need to make jsfiddle account so I can show you guys the code for easy reading, ( sorry guys ) if my English is a not so good,
I am currently learning jQuery, I am not an expert, just a " beginner " ,anyway,
I have made a checkbox and I gave it an id = all
<input type="checkbox" id="all" /><span style='color:red'>All</span>
Simply what I want is, when I click on this checkbox with this specific id = all I want to check these 3 checkboxes listed below
<input type="checkbox" name="us[]" value="google" />Google
<input type="checkbox" name="us[]" value="youtube" />Youtube
<input type="checkbox" name="us[]" value="friend" />Friend<br/><br/>
so this is the code that I some how figured out,
<script type="text/javascript">
$("document").ready(function() {
$("input[id='all']").bind('click',function(){
var all = $(this);
console.log('status: ' + all.prop('checked'));
if(all.prop('checked') == true)
{
//alert('now its true');
$("input:checkbox").attr("checked","checked");
}
else if (all.prop('checked') == false){
$("input:checkbox").removeAttr("checked");
}
})
})
</script>
when i click on the checkbox with id = all ( it selects all checkboxes )
now when I click the second time on the checkbox with id = all ( it unchecked all checkboxes )
every thing is greet untill now
Now the problem when I go to click a third time on the checkbox with id = all
( it does not check any checkboxes ) However when I check the console I see all attributes equal to checked - but the checkboxes I don't see them checked on the browser I mean the checkboxes they don't have this tick mark in the middle of each box, maybe there is something wrong with code, I just can't figure it out why it's not working when I want to click more than 3 times.