VIPStephan
05-23-2007, 05:05 PM
Well, as good as I am with XHTML and CSS as much do I have to learn in JavaScript programming. I’m just beginning to understand and modify the DOM and I ran into something that I couldn’t find a solution for after some extensive search.
I have this function:
if(document.getElementById && document.createElement) {
function addflags() {
var children = document.getElementById('pagelist').childNodes;
for(var i = 0; i < children.length; i++) {
children[0].className = 'bulgaria';
children[1].className = 'england';
children[2].className = 'italy';
children[3].className = 'sweden';
}
}
window.onload = addflags;
}
The XHTML is an unordered list with 4 list items and sub lists in those list items (plus links in each li) and I want to add a country flag (set as background image in the CSS) to the direct children of the ul (the first level list items).
Now I discovered that Firefox is only reacting to odd array numbers, i.e. children[1], 3, 5, and 7 (the even numbers have "no properties") while IE is applying the classes correctly(?) as intended above (0,1,2,3).
At which point did I go wrong?
Sorry if this is a real stupid question but I’m pretty new in this field and my researches didn’t bring any acceptable results.
Thanks.
I have this function:
if(document.getElementById && document.createElement) {
function addflags() {
var children = document.getElementById('pagelist').childNodes;
for(var i = 0; i < children.length; i++) {
children[0].className = 'bulgaria';
children[1].className = 'england';
children[2].className = 'italy';
children[3].className = 'sweden';
}
}
window.onload = addflags;
}
The XHTML is an unordered list with 4 list items and sub lists in those list items (plus links in each li) and I want to add a country flag (set as background image in the CSS) to the direct children of the ul (the first level list items).
Now I discovered that Firefox is only reacting to odd array numbers, i.e. children[1], 3, 5, and 7 (the even numbers have "no properties") while IE is applying the classes correctly(?) as intended above (0,1,2,3).
At which point did I go wrong?
Sorry if this is a real stupid question but I’m pretty new in this field and my researches didn’t bring any acceptable results.
Thanks.