Reputation: 139
I have a script working in Firefox that uses an element array extracted with getElementsByClassName. This method isn't supported in IE8 so I have to substitute querySelectorAll. My problem is querySelectorAll creates a static list, not a live reference to actual elements.
My script
function subMenu(sCat,gCat,sh,gh,selection)
{
sElements = document.querySelectorAll('cat'+sCat);
gElements = document.querySelectorAll('cat'+gCat);
// sElements = document.getElementsByClassName('cat'+sCat);
// gElements = document.getElementsByClassName('cat'+gCat);
if(sh>0)
{
for(i=0;i<sElements.length;i++)
{
if(!(h = window.getComputedStyle(sElements[i],null).height)) {h=sElements[i].currentStyle;}
nh = parseInt(h.replace("px",""))-4;
sElements[i].style.height = nh+"px";
}
sh=sh-4;
}
if(gh<100)
{
for(i=0;i<gElements.length;i++)
{
if(!(h = window.getComputedStyle(gElements[i],null).height)) {h=gElements[i].currentStyle;}
nh = parseInt(h.replace("px",""))+4;
gElements[i].style.height = nh+"px";
}
gh=gh+4;
}
if(sh>0 || gh<100) {xMenu=setTimeout("subMenu("+sCat+","+gCat+","+sh+","+gh+",'"+selection+"')",10);}
else
{
fadeOut(selection);
}
}
I have commented out the script that works fine but not in IE8. I'm not sure whether the getComputedStyle or currentStyle property are working but setting style.height property defintiely isn't.
So my questions:
Is there a way to get a live node list from IE8 similar to getElementsByClassName?
Can anyone suggest a method of converting the array from querySelectorAll into an array of element objects?
Upvotes: 1
Views: 914
Reputation: 94141
querySelectorAll
as the name implies expects a selector. Classes start with a dot, just like in CSS:
sElements = document.querySelectorAll('.cat'+sCat);
-^-
To convert it to a real array:
realArray = Array.prototype.slice.call(pseudoArray);
Upvotes: 1