This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

getElementsByTagNameNS

Summary

Returns an HTMLCollection of the elements with the specified tag name and namespace.

Method of dom/Documentdom/Document

Syntax

var elements = document.getElementsByTagNameNS(namespace, localName);

Parameters

namespace

Data-type
String

The namespace URI that defines the desired elements or an asterisk (*) to match all namespaces with the document, or null.

localName

Data-type
String

The name of the desired element or an asterisk (*) to match all elements with the specified namespace.

Return Value

Returns an object of type ObjectObject

A live HTMLCollection of elements.

Usage

 This method should not be used. For a more performant alternative, see the notes.

Use this method to get a live list of elements with a specified name and namespace.

Notes

  • For performance reasons, querySelectorAll is preferred, because it gets a static list.
  • This method returns a live element list that gets updated whenever an element is added or removed from the document, this has performance implications and may result in unexpected errors (removing elements within a for loop while caching the length of the collection).
  • If namespaces are irrelevant in the context, getElementsByTagName can be used (but it is also not recommended; see the first two notes).

Related specifications

DOM
Living Standard
DOM Level 4
Candidate Recommendation
Document Object Model (DOM) Level 3 Core
Recommendation
Document Object Model (DOM) Level 2 Core
Recommendation

Attributions