IE: apply stylesheet in dynamically inserted nodes
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

IE: apply stylesheet in dynamically inserted nodes

From: Alvaro G Vicario <alvaro_QUITAR_REMOVE@telecomputer.com>
Date: Tue Aug 30 2005 - 15:20:05 CEST

I'm writing a small script to scan an HTML document and append a <span
class="foo">Bar</span> node after each item with certain class name.

My script works fine in Gecko but IE has a serious issue: the CSS style
defined in an external sheet for span.foo is not applied. The generated
HTML shows the correct attribute has been inserted (I can see it with an
old "View Partial Source" hack I've kept for years). Thank you for any
hint.

Here's the relevant code:

// obj is an array with nodes

for(var i=0; i<obj.length; i++){
        // Create the <span>
        var span=document.createElement('span');
        span.setAttribute('class', 'foo';
        
        // Creamos <span>'s content
        var txt=document.createTextNode('Bar');

        // Compose <span>
        span.appendChild(txt);

        // Insertamos <span> in document
        if(obj[i].nextSibling){
                obj[i].parentNode.insertBefore(span, obj[i].nextSibling);
        }else{
                obj[i].parentNode.appendChild(span);
        }
}

-- 
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Received on Tue Oct 18 03:14:31 2005