document.getElementsByTagNameNS(namespace, name) returns a liveHTMLCollection of elements that match both a namespace URI and a local name (MDN). Unlike getElementsByTagName(), both parameters are case-sensitive.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.getElementsByTagNameNS. Start with this line.
JavaScript
document.getElementsByTagNameNS(namespace, name)
Call
What it does
document.getElementsByTagNameNS(namespace, name)
Primary signature.
document.getElementsByTagNameNS(...)
Call with the arguments your case needs.
Built into the browser. Call getElementsByTagNameNS(...) on document — no import required.
Library declarations
JavaScript
document.getElementsByTagNameNS(namespace, name)
Parameters
Parameter
Description
namespace
Required. Namespace URI to match (see element.namespaceURI)
name
Required. Local name, or * for all in that namespace
Return Value
Return Value
Description
*
Live HTMLCollection in tree order
JavaScript Examples
Example 1 — Count XHTML Paragraphs
MDN-style lookup: namespace URI for XHTML plus local name "p".
Correct local name. HTML paragraphs use lowercase p.
Wrong case fails."P" does not match (MDN case-sensitive rule).
Contrast. Plain getElementsByTagName lower-cases in HTML documents.
Rule. Copy namespace URIs and local names carefully — typos yield empty lists.
Compatibility
Browser Support
Document.getElementsByTagNameNS() is Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Document.getElementsByTagNameNS()
Live HTMLCollection by namespace URI and local name across all major browsers.
MDN: it returns a list of elements with the given tag name belonging to the given namespace. The complete document is searched, including the root node.
No. MDN marks Document.getElementsByTagNameNS() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A live HTMLCollection of found elements in the order they appear in the tree (MDN).
You must pass a namespace URI plus a local name. MDN also notes the parameters are case-sensitive, unlike document.getElementsByTagName().
MDN: the special value * matches all elements in that namespace (see element.localName).
Yes. MDN: when the node is not the document, Element.getElementsByTagNameNS() is used to search that subtree.