Problem with JavaScript in IE7

I have been having a problem in IE7 and Internet Explorer 6, by where if you dynamically create a checkbox, set it to checked = true and then add it in to the HTML document, it loses it's checked status.

var newCheck = document.createElement('<input name=relatedSearchesChk>');newCheck.type = "checkbox"; newCheck.onclick = updateCheckStatus;//Function to Call when clickednewCheck.relatedUrl = currSearch.Query;//Expando StringnewCheck.relatedObject = currSearch; //Expand ObjectnewCheck.checked = isChecked; //DOESN't WORK. isChecked is just a local Booelan Variable.tagCell1.appendChild(newCheck);

The closest related problem on the web that I found was this thread: Java Forums - Creating a checked Checkbox through javascript. The solution in this thread works.

However I found another solution. Update the checked status after it has been added to the document. I have no idea why it works like this but it does work.

var newCheck = document.createElement(<input name=relatedSearchesChk>');newCheck.type = "checkbox"; newCheck.onclick = updateCheckStatus;//Function to Call when clickednewCheck.relatedUrl = currSearch.Query;//Expando StringnewCheck.relatedObject = currSearch; //Expand ObjecttagCell1.appendChild(newCheck);newCheck.checked = isChecked; //WORKS

If you know why this happens I would love to know: paul.kinlan@gmail.com

About Me: Paul Kinlan

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.