JavaScript Element getElementsByTagNameNS() Method
Beginner
5 min read
Updated: Nov 2026
3 examples
Method
Definition
In JavaScript, the getElementsByTagNameNS() method returns a liveHTMLCollection of descendants that match a namespace URI and local name (MDN). Search is limited to the element’s subtree — not the element itself.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.getElementsByTagNameNS. Start with this line.
JavaScript
el.getElementsByTagNameNS(ns, localName)
Call
What it does
el.getElementsByTagNameNS(ns, localName)
Primary signature.
el.getElementsByTagNameNS(...)
Call with the arguments your case needs.
Built into the browser. Call getElementsByTagNameNS(...) on an Element — no import required.
Library declarations
JavaScript
el.getElementsByTagNameNS(ns, localName)
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Live HTMLCollection
JavaScript Examples
Example 1 — SVG Circles
Find circle elements in the SVG namespace under a root.
Keep the namespace fixed. Still required as the first argument.
Pass "*" as localName. MDN: matches all elements in that namespace.
Count descendants. Both circle and rect are included.
Root excluded. The svg container itself is not in the collection.
Compatibility
Browser Support
Element.getElementsByTagNameNS() is Baseline Widely available (MDN: across browsers since July 2015). Safe to use in modern evergreen browsers.
✓ Baseline · Widely available
getElementsByTagNameNS()
Live HTMLCollection of descendants matching a namespace URI and local name.
99%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
getElementsByTagNameNS()Excellent
Bottom line: Use for SVG/XHTML/MathML lookups; use getElementsByTagName for ordinary HTML tags when namespaces do not matter.
Frequently Asked Questions
It returns a live HTMLCollection of descendant elements that match a namespace URI and local name. The search is limited to the subtree of the element you call it on (MDN).
No. MDN marks Element.getElementsByTagNameNS() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
namespaceURI — the namespace of elements to find (for example http://www.w3.org/1999/xhtml for XHTML, or http://www.w3.org/2000/svg for SVG). localName — the local tag name, or "*" for all elements in that namespace (MDN).
Use getElementsByTagNameNS() for namespace-aware matching—especially SVG/MathML, or camel-cased SVG tags in HTML where getElementsByTagName() lower-cases the argument (MDN).
Yes. The HTMLCollection updates automatically with the DOM tree, so you usually do not need to call the method again after each change.
Yes. Document.getElementsByTagNameNS() works the same way from the document root; Element.getElementsByTagNameNS() limits the search to one element’s descendants (MDN).