2013年8月4日日曜日

document getAttribute('class') .getAttribute('classname')

getAttribute() メソッドを利用して、class 属性を取得する際に、ブラウザ別に設定が必要になります。

Google Chrome
Mozilla Firefox
の場合  getAttribute('class')


Internet Explorer
の場合  getAttribute('classname')



<script type="text/javascript">
var mv=document.getElementsByTagName('div');
for (var i=0;i<mv.length; i++){
if(mv[i].getAttribute('class')=="item-title" || mv[i].getAttribute('classname')=="item-title"){

document.write(mv[i].innerText + '<br>');

}

}
</script>

0 件のコメント: