****Updated code**** - see note at the bottom.
DOMNodeInserted event that is suggested here is not cross browser, it is not available in ie < 9, and even in ie 9 it is buggy.
A simple cross browser solution would be to set an interval that checks every 100ms, whether all checkbox elements by class name "bad" are disabled:
function CheckBadCheckboxes()
{
var elems = document.getElementsByTagName("input");
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == "checkbox" && /\b(bad)\b/i.test(elems[i].className) && !elems[i].disabled) {
elems[i].disabled = true;
}
}
}
window.setInterval(CheckBadCheckboxes, 100);
This code does not require you to use jQuery.
There is also another argument agains DOMNodeInserted, it is deprecated and degrades performance of a web page. PetersenDidIt explains it in a comment here:
DOMNodeInserted equivalent in IE?
@Anurag Note: The MutationEvent interface was introduced in DOM Level 2 Events, but has not yet been completely and interoperably implemented across user agents. In addition, there have been critiques that the interface, as designed, introduces a performance and implementation challenge. A new specification is under development with the aim of addressing the use cases that mutation events solves, but in more performant manner. Thus, this specification describes mutation events for completeness, but deprecates the use of both the MutationEvent interface and the MutationNameEvent interface.
Buggy behavior of DOMNodeInserted:
http://help.dottoro.com/ljmcxjla.php
Note that the DOMNodeInserted event is buggy in Internet Explorer 9, it is not fired when a node is inserted for the first time. See the examples below for details.
UPDATE.
I've updated my code, earlier I've used getElementsByClassName() which is unfortunately not supported by IE < 9, I've replaced it with getElementsByTagName("input").