CSS does not apply to dynamically created items in IE 7?


Still looking for an answer.

Changing or reassigning to the filter's innerHTML successfully redraws the element, but breaks my script, so that's out.

Adding additional child nodes, including text nodes, does not force a redraw. Removing the added node does not force a redraw.

Using the ie7.js family of scripts does not work.

In the project I am working on, I dynamically generate (with javascript) filters that look like this:

<div class="filter">
    <a ... class="filter_delete_link">Delete</a>
    <div class="filter_field">
    <div class="filter_compare">
    <div class="filter_constraint">
    <div class="filter_logic">

And I have CSS that applies to each filter (for example):

.filter a.filter_delete_link{
    background: url('../images/remove_16.gif') no-repeat;

However, it seems in IE 7 (and probably 6 for that matter), these styles don't get applied to the new filters.

Everything works perfectly in Firefox/Chrome/IE8.

Using the IE8 developer tools, set to IE7 mode, the browser can see the new elements, and can see the CSS, but just isn't applying the CSS.

Is there a way to force IE to reload styles, or perhaps is there a better way to fix this?

The JavaScript: (simplified)

var builder = {
    createNewFilter: function() {
        var newFilter = document.createElement('div');

        var deleteLink = document.createElement('a');
        deleteLink.href = '#';
        deleteLink.title = 'Delete Condition';
        deleteLink.innerHTML = "Delete";

        var field = document.createElement('div');
        var fieldSelect = this.getFieldSelectBox();

        // more of the same...

        deleteLink.onclick = function() {
        fieldSelect.onchange = function () {

        return newFilter;
    addNewFilter: function() {
        var nNewFilter = this.createNewFilter(this.numFilters++);

        //other unrelated stuff...

        //provided by Josh Stodola

        return nNewFilter;

The problem, I've discovered is that IE 6/7 doesn't register the class name changes with elm.setAttribute('class','x') until the UI is redrawn.

The solution is to use the form elm.className = 'x'

**This problem was also noticeable from moving from IE9 quirks to standards mode. The solution was the same.