You are here: Reference > JavaScript > client-side > HTML DOM > methods > tags (all, anchors, areas, ...)
tags method (all, anchors, areas, ...)
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.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
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:
|
||||
<head> <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"; } } </script> </head> <body> <button onclick="UnderlineParagraphs ();">Underline all paragraph elements!</button> <p>apple</p> <p>peach</p> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
all, anchors, applets, areas, boundElements, cells, childNodes, children, elements, embeds, forms, images, links, NodeList, options, rows, scripts, tBodies
HTML elements:
External links:
User Contributed Comments