jQuery日本語リファレンスのあの『ヌー』をJavaScriptで書き換えてみた
みんながお世話になっているjQueryの日本語リファレンス。これの「ヌー」。
//jQuery 4行 $('.semooh a').hover( function(){ $(this).text('ヌ?'); }, function(){ $(this).text('ヌー'); } );
これを、JavaScriptに書き換えてみた。 一応、想定しているhtmlはこんな感じ。
<div class="semooh"> <a>ヌー</a> </div>
//JavaScript 8行 var semooh = document.getElementsByClassName("semooh"); var aElm = semooh[0].getElementsByTagName('a')[0]; aElm.addEventListener( "mouseover", function(){ this.innerHTML = "ヌ?"; }); aElm.addEventListener( "mouseout", function(){ this.innerHTML = "ヌー"; });
こんな感じ。 もっといいやり方があれば教えてください。