Home > IEでclassの値を取得する場合の注意 - JavaScript

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

関連エントリー

コメント

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

コメントを投稿





このエントリーのトラックバックURL

http://www.trapple.net/blog/mt/mt-tb.cgi/17

トラックバック

uk amateurs naked

2007年04月07日 12:54 | uk amateurs naked

the dump furniture store va

2007年04月10日 07:19 | the dump furniture store va

knight porn comic

2007年04月24日 00:09 | knight porn comic