Posted October 26, 2013
getElementById is nice in that it works on pretty much everything, but it is very specific in what it does: find EXACTLY one element whose id attribute EXACTLY matches a given string. If you want more flexibility then it would be better to rely either on querySelector and querySelectorAll or jQuery.
As you can see over here (very useful site) querySelector and querySelectorAll are supported on IE8+ and all other browsers, so its compatibility - while not perfect - is very good. Is your script a userscript like this one, or is it part of a website that you're making? I ask because if it's a userscript then lack of IE7- support doesn't matter because nobody will be using userscripts on those browsers anyway.
All-in-all I think the best thing would be to go and learn jQuery - it'll make this sort of thing extremely easy for you.
I'd be happy to help with any scripting-related questions you might have, and I'm sure that a few other people here would too. A good idea would be for you to create a new thread and ask your questions there - you'll get the most assistance that way, as everyone will be able to see what the discussion is about by looking at the thread title.
As you can see over here (very useful site) querySelector and querySelectorAll are supported on IE8+ and all other browsers, so its compatibility - while not perfect - is very good. Is your script a userscript like this one, or is it part of a website that you're making? I ask because if it's a userscript then lack of IE7- support doesn't matter because nobody will be using userscripts on those browsers anyway.
All-in-all I think the best thing would be to go and learn jQuery - it'll make this sort of thing extremely easy for you.
I'd be happy to help with any scripting-related questions you might have, and I'm sure that a few other people here would too. A good idea would be for you to create a new thread and ask your questions there - you'll get the most assistance that way, as everyone will be able to see what the discussion is about by looking at the thread title.