Skip to main content
Interpretation of sentence near "a new post on that".
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

toTo check a check boxcheckbox you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false:

 $('.myCheckbox').attr('checked',false);

ifIf you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form.

BAD DEMO jQuery 1.6 i. I think this is broke itbroken. For 1.6 gonnaI am going to make a new post on that.

NEW WORKING DEMO jQuery 1.5.2 this works in chromeChrome.

bothBoth demos use

$('#tc').click(function() {
    if ( $('#myCheckbox').attr('checked')) {
        $('#myCheckbox').attr('checked', false);
    } else {
        $('#myCheckbox').attr('checked', 'checked');
    }
});

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

BAD DEMO jQuery 1.6 i think this is broke it 1.6 gonna make a new post on that

NEW WORKING DEMO jQuery 1.5.2 this works in chrome

both demos use

$('#tc').click(function() {
    if ( $('#myCheckbox').attr('checked')) {
        $('#myCheckbox').attr('checked', false);
    } else {
        $('#myCheckbox').attr('checked', 'checked');
    }
});

To check a checkbox you should use

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set it to false:

 $('.myCheckbox').attr('checked',false);

If you do

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form.

BAD DEMO jQuery 1.6. I think this is broken. For 1.6 I am going to make a new post on that.

NEW WORKING DEMO jQuery 1.5.2 works in Chrome.

Both demos use

$('#tc').click(function() {
    if ( $('#myCheckbox').attr('checked')) {
        $('#myCheckbox').attr('checked', false);
    } else {
        $('#myCheckbox').attr('checked', 'checked');
    }
});
added 423 characters in body
Source Link
mcgrailm
  • 17.7k
  • 22
  • 85
  • 131

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

WORKINGBAD DEMO jQuery 1.6 i think this is broke it 1.6 gonna make a new post on that

NEW WORKING DEMO jQuery 1.5.2 this works in chrome

both demos use

$('#tc').click(function() {
    if ( $('#myCheckbox').attr('checked')) {
        $('#myCheckbox').attr('checked', false);
    } else {
        $('#myCheckbox').attr('checked', 'checked');
    }
});

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

WORKING DEMO

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

BAD DEMO jQuery 1.6 i think this is broke it 1.6 gonna make a new post on that

NEW WORKING DEMO jQuery 1.5.2 this works in chrome

both demos use

$('#tc').click(function() {
    if ( $('#myCheckbox').attr('checked')) {
        $('#myCheckbox').attr('checked', false);
    } else {
        $('#myCheckbox').attr('checked', 'checked');
    }
});
added 61 characters in body
Source Link
mcgrailm
  • 17.7k
  • 22
  • 85
  • 131

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

WORKING DEMO

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

to check a check box you should use this

 $('.myCheckbox').attr('checked',true);

or

 $('.myCheckbox').attr('checked','checked');

and to uncheck a check box you should always set set it to false

 $('.myCheckbox').attr('checked',false);

if you do this

  $('.myCheckbox').removeAttr('checked')

it removes the attribute all together and therefore you will not be able to reset the form

WORKING DEMO

deleted 107 characters in body
Source Link
mcgrailm
  • 17.7k
  • 22
  • 85
  • 131
Loading
Source Link
mcgrailm
  • 17.7k
  • 22
  • 85
  • 131
Loading