You are here: Reference > JavaScript > client-side > HTML DOM > methods > tags (all, anchors, areas, ...)

tags method (all, anchors, areas, ...)

Browser support:
Returns a NodeList collection that contains all elements from the current collection with the specified tag name.
The tags method works on collections like the getElementsByTagName method on elements.


object.tags (tagName);
You can find the related objects in the Supported by objects section below.


Required. String that specifies the tag name to look for.

Return value:

Returns a NodeList collection filled with the matching elements. The elements in the returned collection are in source order.

Example HTML code 1:

This example illustrates the use of the tags method:
    <script type="text/javascript">
        function UnderlineParagraphs (){
            if (document.all && document.all.tags) {
                var pTags = document.all.tags ("p");
            else {
                var pTags = document.getElementsByTagName ("p");

            for (var i=0; i < pTags.length; i++) {
                pTags[i].style.textDecoration = "underline";
    <button onclick="UnderlineParagraphs ();">Underline all paragraph elements!</button>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content