Wednesday, December 13, 2006

element.getAttribute("class")

Why are even the simple things sometimes hard? Attempting to get a element attribute. Here is a table of what the various browsers return when trying to get the class attribute having already found an element:
var element = document.getElementById("theSpan");
in a document containing the HTML:
<span id="theSpan" class="something">
Browser element. getAttribute( "class" ); element. getAttribute( "CLASS" ); element. getAttribute( "className" ); element. attributes[ "class" ]; element. className;
Firefox 2.0 something something null [object Attr] something
Opera 9.0 something something null [object Attr] something
Safari 1.3.2 something something null undefined something
IE 5.5 (Mac) null null something something something
IE 7.0 null null something [object] something

Updated: Thanks to anonymous for pointing out that you can just use element.className to get the class name used and it seems to work correctly across all browsers I tested.

It seems that there is no simple way to get the class attribute across browsers. The solution seems to be to get the class attribute and if it undefined try the className attribute. Most other attributes should work fine, it is just that IE doesn't like the class attribute that throws the spanner in the works. Here is the quick testing page.

Tuesday, December 12, 2006

Label Based Feeds

When I was at the Sakai conference I was asked if I wanted my blog added to Sakai Planet, the thing is that I blog about more than just Sakai and so only the posts for Sakai should end up in the planet. After a little googling I discovered you can have feeds for labels and it seems that my sakai feed works. I wonder why Google don't make this the default RSS feed when viewing all the posts for a tag?