nodeName Property

calendar November 26, 2009

Value: string

Compatibility: WinIE5+, MacIE5+, Moz1+, Safari1+

For HTML and XML elements the name of a node is the same as the tag name. The value is an all-uppercase string of the tag name.

Some nodes such as the text content of an element do not have a tag, the nodeName property is a special value: #text.

The following example demonstrates one way to assing a new class name to every p element in an IE5+ document:

function setPClasses(className)
{
  for(var i = 0; i < document.all.length; i++)
  {
    if(document.all[i].nodeName == "P")
    {
      document.all[i].className = "className";
    }
  }
}

Related item: tagName property

admin

Leave a Reply

You must be logged in to post a comment.