JavaScript Samples
Dom編

nodeName
説明 :
対象ノード名
インターフェイス :
/Core/Node
read/write :
readonly
Syntax :
oj.nodeName
値 :
値はそのノードのタイプによって異なる。下表のnodeName列を参照。
Interface nodeName nodeValue attributes
Attr アトリビュート名( Attr.nameと同じ) Attr.valueと同じ null
CDATASection "#cdata-section" CharacterData.dataと同じ, CDATA セクション null
Comment "#comment" CharacterData.dataと同じ, コメント null
Document "#document" null null
DocumentFragment "#document-fragment" null null
DocumentType document type 名 DocumentType.name null null
Element タグ名 Element.tagName null NamedNodeMap
Entity エンティティ名 entity name null null
EntityReference 参照されるエンティティ名  entity referenced null null
Notation 表記法名 notation name null null
ProcessingInstruction ターゲット ProcessingInstruction.target ProcessingInstruction.dataと同じ null
Text "#text" CharacterData.dataと同じ, テキストノード null


サンプル : 1 (Elementの場合)

test1test2

<p id="pid"><i>test1</i><b>test2</b></p>
<form>
  <input type    = "button"
         value   = "クリックしてください"
         onclick = "
                  oj = document.getElementById('pid')
                  alert( oj.firstChild.nodeName )
  ">
</form>
クリックすると、<p id="pid">の最初の子ノード <i>test1</i> のノードネーム(タグ名「I」)が表示されます。
*この場合はfirstChildがタグだったのでタグ名が表示されましたが、もし、文字列の場合は次のようになります。


サンプル : 2 (Textの場合)

文字列1test1test2

<p id="pid2">文字列1<i>test1</i><b>test2</b></p>
<form>
  <input type    = "button"
         value   = "クリックしてください"
         onclick = "
                  oj = document.getElementById('pid2')
                  alert( oj.firstChild.nodeName )
  ">
クリックすると、<p id="pid">の最初の子ノード 文字列1 のノードネーム(#text)が表示されます。


サンプル : 3
DIV
DIV
SPAN
DIV
<script>
<!--
  function big(oj){
    if( oj.nodeName == 'SPAN' )
      oj.style.fontSize = "20px"
  }
  function sml(oj){
    if( oj.nodeName == 'SPAN' )
      oj.style.fontSize = "1em"
  }
//-->
</script>
<div  onmouseover = "big(this)"
      onmouseout  = "sml(this)">DIV</div>
<div  onmouseover = "big(this)"
      onmouseout  = "sml(this)">DIV</div>
<span onmouseover = "big(this)"
      onmouseout  = "sml(this)">SPAN</span>
<div  onmouseover = "big(this)"
      onmouseout  = "sml(this)">DIV</div>
マウスカーソルが触れると spanタグ の時だけフォントサイズが大きくなります