Export (0) Print
Expand All

tags method

Retrieves a collection of objects that have the specified HTML tag name.

Syntax

object.tags(tagName)

Parameters

tagName [in]

Type: DOMString

Specifies an HTML element. It can be any one of the objects exposed by the DOM

Return value

Type: Object

Returns a collection of element objects if successful, or null otherwise.

Standards information

There are no standards that apply here.

Remarks

Successful execution includes the case where no elements having the given name are found. In this case, a collection containing zero elements is returned.

The length property of the collection contains the number of elements in the collection.

NULL may be returned in cases where the collection cannot be constructed, such as inability to allocate memory for even a zero-length collection.

Examples

This example uses the tags method to retrieve a collection of all p elements in the document, and all body elements in the document. It displays some of the properties of the collections that are returned. It then displays selected elements of the collection. There are no p elements in the document, and there is one body element in the document. So, this example illustrates both the cases where the collection is empty and where the collection is populated.



<html>
<head>
<title>document.all.tags example </title>
</head>
<body>
<script type="text/jscript" language="jscript">
document.write("Here is how document.all.tags behaves when no tags are found.<br>");
var coll = document.all.tags("p");
document.write("list 'p' tags" + "<br>");
document.write("coll= " + coll + "<br>");
document.write("coll.length= " + coll.length + "<br>");
if (coll==null){
    document.write( "coll= is null <br>" );
} else {
    document.write( "coll= is not null <br>" );
}
if ( coll[0] != null ){
    document.write( "coll[0].attributes length " + coll[0].attributes.length  + "<br>");
    for ( i = 0; i<coll[0].attributes.length ; i++ ){
        if (( coll[0].attributes[i].value       != "null"  )
           &( coll[0].attributes[i].value.length > 0       ))
        {
            document.write( "coll[0].attributes "        + i + ":"   );
            document.write(  coll[0].attributes[i].name      + ":            "   );
            document.write(  coll[0].attributes[i].value     + "<br>");
        }
    }
}
document.write( "<br><br>" );
document.write( "Here is how document.all.tags behaves when at least 1 tag is found.<br>" );
var coll = document.all.tags( "body" );
document.write( "list 'body' tags"            + "<br>" );
document.write( "coll= "        + coll        + "<br>" );
document.write( "coll.length= " + coll.length + "<br>" );
if ( coll == null ){
    document.write( "coll= is null <br>" );
} else {
    document.write( "coll= is not null <br>" );
}
if ( coll[0] != null ){
    document.write( "coll[0].attributes length " + coll[0].attributes.length  + "<br>");
    for ( i = 0; i<coll[0].attributes.length ; i++ ){
        if (( coll[0].attributes[i].value       != "null"  )
           &( coll[0].attributes[i].value.length > 0       ))
        {
            document.write( "coll[0].attributes "        + i + ":"   );
            document.write(  coll[0].attributes[i].name      + ":            "   );
            document.write(  coll[0].attributes[i].value     + "<br>");
        }
    }
}
</script>
<pre>
=================================
== Here is what the above example should display
=================================
Here is how document.all.tags behaves when no tags are found.
list 'p' tags
coll= [object]
coll.length= 0
coll= is not null
Here is how document.all.tags behaves when at least 1 tag is found.
list 'body' tags
coll= [object]
coll.length= 1
coll= is not null
coll[0].attributes length 98
coll[0].attributes 21:hideFocus: false
coll[0].attributes 45:contentEditable: inherit
coll[0].attributes 59:disabled: false
coll[0].attributes 69:tabIndex: 0
coll[0].attributes 80:bottomMargin: 15
coll[0].attributes 81:noWrap: false
coll[0].attributes 90:leftMargin: 10
coll[0].attributes 92:topMargin: 15
coll[0].attributes 95:rightMargin: 10
</pre>
</body>
</html>


See also

all
anchors
applets
areas
boundElements
cells
children
elements
embeds
form
forms
images
links
options
rows
scripts
select
tBodies

 

 

Show:
© 2014 Microsoft