Modern jQuery
Use .prop()
:
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
DOM API
If you're working with just one element, you can always just access the underlying HTMLInputElement
and modify its .checked
property:
$('.myCheckbox')[0].checked = true;
$('.myCheckbox')[0].checked = false;
The benefit to using the .prop()
and .attr()
methods instead of this is that they will operate on all matched elements.
jQuery 1.5.x and below
The .prop()
method is not available, so you need to use .attr()
.
$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);
Note that this is the approach used by jQuery's unit tests prior to version 1.6 and is preferable to using $('.myCheckbox').removeAttr('checked');
since the latter will, if the box was initially checked, change the behaviour of a call to .reset()
on any form that contains it – a subtle but probably unwelcome behaviour change.
For more context, some incomplete discussion of the changes to the handling of the checked
attribute/property in the transition from 1.5.x to 1.6 can be found in the version 1.6 release notes and the Attributes vs. Properties section of the .prop()
documentation.
Your array has one element, which is an object, so filter[0]
gives you that object.
That object has two properties, assignment
and cell
, so filter[0].assignment
gives you "Tom" and filter[0].cell
gives you the inner array.
The inner array has filter[0].cell.length
items in it, the first of which is filter[0].cell[0]
, the second of which is filter[0].cell[1]
, etc.
To iterate over the items in the inner array do this:
for(var k = 0; k < filter[0].cell.length; k++){
if(filter[0].cell[k]==option){
newTable.push(filter[0].cell[k]);
break;
}
}
...but it's kind of clunky repeating filter[0].cell
everywhere, so you can add another variable that is a reference to the inner array:
var cell = filter[0].cell;
for(var k = 0; k < cell.length; k++){
if(cell[k]==option){
newTable.push(cell[k]);
break;
}
}
Your code that tried to use filter[0][0][0].value
didn't work because you can't access object properties by numeric index except where the actual property name is a number, and in any case you don't want the .value
bit on the end.
Best Answer
If you want the slices with percent only (no label), you need to define a custom
formatter
for the label option:Fiddle here.