IE and my javascript: not working
For some reason IE doesnt like my javascript below:
ciao.getElementsByClassName('wp-caption-text').item(0).appendChild(d);
Has anyone got any ideas. The error I am recieving is below:
Webpage error details
Message: Object doesn't support this property or method
Line: 277
Char: 15
Code: 0
If someone can figure this out I would think they were a genious. I know it is this line because I changed the code and it worked. Basically I created an array and did a for loop.
teammatt3 posted this at 20:32 — 19th June 2009.
He has: 2,102 posts
Joined: Sep 2003
getElementsByClassName doesn't work in IE. IE doesn't implement it.
You'll need to roll your own method, or use a Javascript library like jQuery (there are a dozen of them, but I like jQuery).
If you want to create your own, a quick Google search turned this code up:
document.getElementsByClassName = function(clsName){
var retVal = new Array();
var elements = document.getElementsByTagName("*");
for(var i = 0;i < elements.length;i++){
if(elements[i].className.indexOf(" ") >= 0){
var classes = elements[i].className.split(" ");
for(var j = 0;j < classes.length;j++){
if(classes[j] == clsName)
retVal.push(elements[i]);
}
}
else if(elements[i].className == clsName)
retVal.push(elements[i]);
}
return retVal;
}
benf posted this at 21:04 — 19th June 2009.
They have: 426 posts
Joined: Feb 2005
IE is a bag of C**P!
Thanks mate.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.