thanks for helping... I'm creating a series of html elements in javascript, including checkboxes. I want to go ahead and mark one of the checkboxes by default. I cannot get the 'checked' property to exist using either pure javascript (checkbox.checked = true;) or jquery library (see below). See my example, thank you - EDIT: The pure jQuery solution does work, but I'm having trouble with a javascript solution. Subsequent checkbox elements seem to inhibit the 'checked' attribute on prior ones. See this fiddle for an example...fiddle example
function createToolbarElements(){
//------topbar-------------
var topbar = document.getElementById("topbar");
topbar.innerHTML = "ZONE: ";
//zone set
ART.regions.unshift("All");
ART.regions.push("osj");
var numRegions = ART.regions.length;
var region;
for(i=0; i<numRegions; i+=1){
region = ART.regions[i];
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = region;
checkbox.value = region;
checkbox.id = "zone"+region;
if(region === "All"){
$("#zoneAll").prop("checked", true);
}
topbar.appendChild(checkbox);
var label = document.createElement('label')
label.htmlFor = region;
label.appendChild(document.createTextNode(region));
topbar.appendChild(label);
}
}
here's the HTML:
<div id="topbar" style="z-index: 2; position:absolute; height: 24px; padding: 4px;
background-color: #DDD; color:#111; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;
font-size:10pt; line-height:1.2">
</div>
#).$("#zoneAll").prop("checked", true);or evendocument.getElementById('zoneAll').checked = truethen instead of checking each iteration?