Anchors Definition and Usage..
The anchors collection returns a collection of all elements in the document that have a name attribute.
Note: The name attribute of the element is not supported in HTML5.
The elements in the collection are sorted as they appear in the source code.
Tip: Also look at the Anchor Object and document.links.
Syntax: document.anchors
Links Definition and Usage..
The links collection returns a collection of all links in the document.
The links in the collection represents elements and/or elements with a href attribute.
Note: If the element is missing the href attribute, nothing is returned.
Note: The elements in the collection are sorted as they appear in the source code.
Syntax: document.links
CODING:The anchors collection returns a collection of all elements in the document that have a name attribute.
Note: The name attribute of the element is not supported in HTML5.
The elements in the collection are sorted as they appear in the source code.
Tip: Also look at the Anchor Object and document.links.
Syntax: document.anchors
Links Definition and Usage..
The links collection returns a collection of all links in the document.
The links in the collection represents elements and/or elements with a href attribute.
Note: If the element is missing the href attribute, nothing is returned.
Note: The elements in the collection are sorted as they appear in the source code.
Syntax: document.links
<!DOCTYPE html>
<html>
<body>
<a name="js" href="JS_HOME.html">JAVA SCRIPT</a><br>
<a name="php">PHP</a><br>
<a name="xml" href="XML_HOME.html">XML</a><br>
<p>Click the button to display the number of anchors in the
document.</p>
<button onclick="myFunction()">Click ME!</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = "Total Link:" + document.links.length;//anchors.length;
var y = "<br>1st Link:" + document.links[0].innerHTML;//anchors[0].innerHTML;
var z = "<br>1st Link Ref.:"+ document.anchors.item(0);//links.item(0).href;
z = z + "<br>2nd Link Ref.:" +document.anchors.namedItem("xml");document.getElementById("demo").innerHTML = x + y + z;
}
</script>
</body>
</html>
<html>
<body>
<a name="js" href="JS_HOME.html">JAVA SCRIPT</a><br>
<a name="php">PHP</a><br>
<a name="xml" href="XML_HOME.html">XML</a><br>
<p>Click the button to display the number of anchors in the
document.</p>
<button onclick="myFunction()">Click ME!</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = "Total Link:" + document.links.length;//anchors.length;
var y = "<br>1st Link:" + document.links[0].innerHTML;//anchors[0].innerHTML;
var z = "<br>1st Link Ref.:"+ document.anchors.item(0);//links.item(0).href;
z = z + "<br>2nd Link Ref.:" +document.anchors.namedItem("xml");document.getElementById("demo").innerHTML = x + y + z;
}
</script>
</body>
</html>
Comments
Post a Comment