Forum Moderators: open
It works fine in FF but not in others. Here is a sample of my code where the prob is occuring
if(s.display=='none') {
for(i=parseInt(idLevel); i<opened.length; i++){//close open ones higher than selected uip
document.getElementById(opened[i]).style.display = 'none';
}
//splice the array anmd then display correcr
opened.splice(parseInt(idLevel));
s.display = 'block';
opened[opened.length] = id;
} else {
for(i=parseInt(idLevel); i<opened.length; i++){//close open ones higher than selected uip
document.getElementById(opened[i]).style.display = 'none';
}
s.display = 'none';
opened.splice(parseInt(idLevel));
}
See:
[w3schools.com...]
You need to specify 2 parameters, the first being the index, the second being how many elements to remove. You can also specify replacement elements, hence the definition of the word splice.
Hope this solves it.
No, there is not a compatibility problem in IE and Opera, ...
w3schools does state the 2nd argument as being reqd and for browser compatibility I think it is. However, I have read several sources that state the 2nd arg as optional...
JavaScript: The Definitive Guide, 4th Edition By David Flanagan:
If this second argument is omitted, all array elements from the start element to the end of the array are removed.
And this is how it works in FF1.5, but not in IE6 or Op8 (both seem to default the 2nd arg to 0 [zero]). I suppose this could be a browser compatibility problem.
<edit>
Just to add, IE 5.01 does not support
splice()at all, in case you still need to support that browser?!
If this second argument is omitted, all array elements from the start element to the end of the array are removed
Didn't realise that, but I'd still say the W3Schools is correct, and that is a side effect.
Infact, just after I wrote that I looked it up on Mozilla's developer website:
[developer.mozilla.org...]
The 2nd argument is not optional.