JavaScript Tutorial/Document/all
Содержание
document.all
Syntax
document.all[index]
The document.all property is an array of all the HTML elements that are in the document.
The elements appear in the array in the order in which they were created.
Methods Associated with the document.all Array
Method Description item() Returns an HTML element based on element"s name tags() Returns an array of elements that have the specified tag
document.all.item()
Syntax
document.all.item(name)
document.all.tags()
Syntax
document.all.tags(tag)
List all elements by reference the document.all
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
function findhead1()
{
var tag, tags;
tags = "The tags in the page are:"
for(i = 0; i < document.all.length; i++)
{
tag = document.all(i).tagName;
tags = tags + "\r" + tag;
}
document.write(tags);
}
// -->
</script>
</head>
<body onload="findhead1()">
<h1>Heading One</h1>
</body>
</html>
Use document.all(elementId) to get the element
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
function findhead1()
{
var detectElement;
detectElement = document.all("head1");
if (detectElement == head1)
{
alert("Element \"head1\" exists");
}
}
// -->
</script>
</head>
<body onload="findhead1()">
<h1 id="head1">Heading One</h1>
</body>
</html>