This is the initial creation. Code :
VaR CB = Document. createelement ( " Input " );
CB. Type = " Checkbox " ;
This is the code to add the checxbox control to the Container Control. LB. appendchild (CB );
Initialize the checked value before adding it to the parent container.
CB. Checked = True ;
Or:
CB. setattribute ( " Checked " , True );
However, in Firefox, the statement CB. Checked = true is not supported. It may be that the checked in Firefox is a read-only attribute.
Compatible Syntax:
Window. onload = function (){
VaR lB = Document. createelement ("label ");
VaR cb = Document. createelement ("input ");
CB. type = "checkbox ";
CB. value = 1;
CB. ID = "cb_a ";
Lb.html for = "cb_a ";
LB. appendchild (CB );
Document. Body. appendchild (LB );
CB. setattribute ("checked", true );
LB. innerhtml + = "Click me to select me ";
The cb id and LB htmfor attribute are added to ensure compatibility with ie6.