473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

IE: apply stylesheet in dynamically inserted nodes

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
--
Aug 30 '05 #1
3 2115


Alvaro G Vicario wrote:

var span=document.createElement('span');
span.setAttribute('class', 'foo';


Don't use setAttribute, use
span.className = 'foo';
instead and your cross browser problems go away.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 30 '05 #2

As Martin said, IE does have issues with .setAttribute().
Danny
Aug 31 '05 #3
*** Martin Honnen wrote/escribió (Tue, 30 Aug 2005 15:48:28 +0200):
var span=document.createElement('span');
span.setAttribute('class', 'foo';


Don't use setAttribute, use
span.className = 'foo';
instead and your cross browser problems go away.


Oh my, the solution is always soooo evident after you've been told! Thanks
a lot.
--
-- Á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
--
Aug 31 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stefan Siegl | last post by:
Hello, I am trying to learn XSLT to use it in another project. I start reading the book "Java and XSLT" and tried the examples and they are went quite fine (how suprising *g*). Then I tried...
1
by: Daryl | last post by:
Hello I am using apply-templates and would like to pass a parameter to the template using with-param. Using call-template passes the parameter, but when I use apply-templates, the parameter seems...
1
by: Vijay singh | last post by:
Hi wonder if anybody can clear by doubt XML file : <score id="1"> <film>A Little Princess</film> <composer>Patrick Doyle</composer>
3
by: bjam | last post by:
Help! The apply-templates function is not currently allowing me to select a specific template... eventhough I tried putting a select statement, it does not seem to work??? Can someone help show...
2
by: jimbo_vr5 | last post by:
Hey I think i've figured out the idea behind apply-templates. But going through the tutorial on <http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply just something that i dont...
4
by: Robert | last post by:
Are there any other ways to dynamically apply CSS styling to a page (without using inline CSS)? I'm sure I could dynamically generate a new and uniquely named CSS file "on the fly" when users...
1
by: j_mckitrick | last post by:
Hi all, I'm making Ajax-type calls that return XML, and rather than parsing the XML with DOM and building the nodes by hand, it seems much better and well-designed to get the XML response, get...
1
by: arunsh | last post by:
Hi I want an equivalent of what the getChildNodes() method does in xsl style sheet. (Note that the getChildNodes() method returns an array of nodes u nder the current node; ) My xml is...
3
by: abhishek.smu | last post by:
Given an XML like: <root> <node>8</node> <node>21</node> <node>-7</node> <node>13</node> <node>43</node> <node>2</node> </root>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.