JSFiddle - React, Tailwind, and code Playground

by protoriumatwork

HTML

<div id="container">
  <input type="checkbox" id="foo" />
  <button id="toggle"> Toogle checked  state </button>
</div>

JavaScript

//Following the recommendation  on
//http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_check.2Funcheck_a_checkbox_input_or_radio_button.3F
//true/false  is used as 2nd argument to attr when setting checked
var obj = $("<input />").attr({"type":"checkbox","id":"someid","name":"somename"});
obj.attr( "checked", true);

if ($('#container').length > 0) {
    obj.appendTo($('#container'));
}

alert("In  IE6.0 at this point the appending checkbox does not have the value  checked assigned presumably because the object we're working on does not  yet exist in the document. Now the object exists, the next line for IE6 will work.");

$('#someid').attr("checked", true);

$( "#toggle" ).toggle(
    function() {
        $( "#foo" ).attr( "checked", true );
    },
     function() {
        $( "#foo" ).attr( "checked", false );
    }
);