IEでclassの値を取得する場合の注意 - JavaScript
JavaScriptのDomにおいて、エレメントの属性値を取得するメソッドはgetAttribute('属性名')
<a class="foo" href="#">bar</a>なエレメントにおいてclassの値を取得するには、通常obj.getAttribute('class')でいいのですが、IEは属性値をclassNameにしないととれません
var attr = obj.getAttribute('class'); //IE以外
var attr = obj.getAttribute(className); //IE
二つまとめると、下記のように書けます。
var attr = obj.getAttribute('class') || obj.getAttribute(className);
[関連記事]
JavaScript++かも日記
IE の getAttribute / setAttribute: Days on the Moon
このエントリーのトラックバックURL
http://www.trapple.net/blog/mt/mt-tb.cgi/17
コメント
Some people think that they are way too smart. They think their comments are wonders of the world! Dudes don’t be so self-confident.
投稿者: Matthieu | 2008年04月07日 05:07