2011年2月10日木曜日

タグの間に文字を埋め込む

  innerHTMLプロパティを使ってもよいが、innerTextの方が速度が速いらしい。
  ただし、FireFoxでは、innerTextが表示されないので、textContent を使う。

  <サンプル>
    var selstr, elm;

    selstr = "Hello";
    elm = document.getElementById(target_dtl);
    if (typeof elm.textContent != "undefined") {
      elm.textContent = selstr;   // for FireFox
    }
    else {
      elm.innerText = selstr;
    }


  [参考サイト]
  http://filipo.cocolog-nifty.com/blog/2007/05/firefoxinnertex_916a.html

  innerHTMLとinnerText/textContentの速度比較
  http://www.openspc2.org/JavaScript/Web_Standard/202/index.html