There was a time when web developers wonder why there was support for getElementsByID but nothing for getElementsByClass or something like that. Developers had got used to writing hacks to get around this and although some javascript libraries do have functions to do this, they are still custom built instead of a native support by the HTML specification.
The good news is, HTML5 is now supporting getElementsByClassName!
getElementsByClassName()
To select elements by their class name. The way this method is defined it will allow it to work for any content with class attributes and a Document object such as SVG and MathML.
So the next question would be: what browsers supports HTML 5 and for the sake of this discussion, getElementsByClassName ?
1. Firefox 3 has some basic support for HTML 5 but not sure if it supports getElementByClassName yet.
2. Forget about Internet Explorer and Safari, they are ALWAYS the slowest to adopt any new web standards. Internet Explorer 8 beta contain support for portions of HTML 5, but not sure whether getElementsByClassName is yet.
3. Safari has really made some major improvements and with the release of Safari 3, not only can it run on Mac OS, but it’s now now available on Windows too. If you’re a web developer, remember to check out their new developer tool named “Web Inspector”.
Safari/WebKit are actively implementing major portions of HTML 5 and includes support for getElementsByClassName, as mentioned in this comment
4. Opera 9.5 is leading the pack currently whereby the browser supports the following HTML 5 components:
– The Canvas element
– contentEditable
– Cross-document messaging
– Element.tabindex attribute and the Element, {blur, focus} methods
– getElementsByClassName
– Embed and Video
– Navigator.onLine attribute and the Window, {online,offline} events
– Server-sent events
– Web Forms 2.0
It will be quite some time before HTML5’s specification is finalised and before major web browsers starts supporting all of those new features. But at least, there’s progress!
The HTML5 draft specification provides more insights to what’s coming and I recommend every web developer to have a look at it.
oOFooi says
Hey… Great. I got to catch up with the fast moving technology. Thanks for sharing.
Shawn Medero says
> “Forget about Internet Explorer and Safari, they are ALWAYS the slowest to adopt any new web standards.”
Safari/WebKit are actively implementing major portions of HTML 5:
* http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage/
* http://webkit.org/blog/140/html5-media-support/
Including support for getElementsByClassName in WebKit:
* http://webkit.org/blog/153/webkit-gets-native-getelementsbyclassname/
The Internet Explorer 8 betas contain support for portions of HTML 5 too:
* http://ejohn.org/blog/javascript-in-internet-explorer-8/
David says
Appreciate the input, Shawn.
I have made changes to my original article about Safari. My experience on Safari wasn’t that concrete as it wasn’t until Safari 3 that it can be run on windows. Web Inspector wasn’t available until Safari 3 as well.