So first off I am learning JS and will not use a library until I know all I need to.
http://www.tombarrasso.com/search/
With that said why on earth does my code not work in < IE 7, Firefox < 3, etc? Safari 4 is perfect, Firefox 3.5 is great, etc. I am using the function getElementsByClassName from Robert Nyman.
It generates no errors in my IE 6 on OS X (through Wine). The Ajax request is fine, but there should be an initial div with id="one" and class="scroller", but there is not. I am just getting so frustrated with this.
Thanks,
..or you can use this as a better solution...
if (typeof document.getElementsByClassName!='function') {
document.getElementsByClassName = function() {
var elms = document.getElementsByTagName('*');
var ei = new Array();
for (i=0;i<elms.length;i++) {
if (elms[i].getAttribute('class')) {
ecl = elms[i].getAttribute('class').split(' ');
for (j=0;j<ecl.length;j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
} else if (elms[i].className) {
ecl = elms[i].className.split(' ');
for (j=0;j<ecl.length;j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
}
}
return ei;
}
}
Personally, I would just use jQuery, as it already has the browser-compatability problems you are running into.
It's all fine to learn it all; but when it comes to handling implementation compatability it's better to have it dealt with for you, IMHO. There are just some things I don't care about :P
IE8 gives error -"Object doesn't support property or method" when we use getElementsByClassName in javascript. Try this instead.
if (document.getElementsByClassName) {
var obj = document.getElementsByClassName('classA');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With