3つのクラスがあるとします
<div class="hello world_1"></div>
<div class="hello world_2"></div>
<div class="hello world_3"></div>
「hello」からクラス名「world_1」「world_2」「world_3」を取得したい。コード:
$('.hello').each(function(){
this.attr('class');
});
次のエラーが発生しました:
TypeError: Object #<HTMLDivElement> has no method 'attr'
少し実験してわかったこと
$('.hello:first').attr('class')
しながら働く
$('.hello')[0].attr('class')
上記のエラーが発生します。
なぜそれが起こったのか、どうすれば欲しいものを手に入れることができるのか、誰か説明できますか?
ありがとう