DIG 4.8. getElementByClassName inserd of getElementById

Subscribe to DIG 4.8. getElementByClassName inserd of getElementById 4 posts, 3 voices

 
hofi Scriptwright

Hello
I want to Insert content after an element by class name.

i have replaced document.getElementById with document.getElementByClassName it this script http://diveintogreasemonkey.org/patterns/insert...

var navbar, newElement;
navbar = document.getElementByClassName('navbar');
if (navbar) {
newElement = document.createElement('hr');
navbar.parentNode.insertBefore(newElement, navbar.nextSibling);
}

But it doesn't work. Can somebody explain me why it doesn't work, and what to do to make it work?
Thanks

 
hofi Scriptwright

I just find out that theres no such thing as document.getElementByClassName :/

 
Aquilax Scriptwright

From firefox 3.0

http://developer.mozilla.org/en/docs/DOM:docume...

 
sizzlemctwizzle Scriptwright

damn I can't wait for firefox 3 to roll out. it really doesn't matter though because it would mean forcing users to update first before they can use your script. here's a little function though. I'm having problems getting it to work with the XPCNativeWrapper. Can anyone help me out?

document.getElementsByClassName = function(className) {
var wrapper = new Array();
for (var dev = this.evaluate('//*[@class="'+className+'"]', this, null, 6, null), i = 0, div; div = dev.snapshotItem(i); i ++)  {
wrapper.push(div);
}
return wrapper;
}

elements = document.getElementsByClassName("YOUR_CLASS_NAME");