Anchor nameProperty

Anchor 对象参考手册Anchor Object

Definition and Usage

The name property sets or returns the value of the name attribute of a link.

The name property returns the name of a link, usually used to create a bookmark in a document.

Syntax

Set the name property:

anchorObject.name="name"

Return the name property:

anchorObject.name

Value Description
name Sets the name of a link.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the name attribute.


Example

Example

Return the name of the link:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
</head>
<body>

<p><a href="../index.html">See Chapter 6</a></p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 4</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 5</h2>
<p>This chapter explains ba bla bla</p>
<h2><a id="c6" name="C6">Chapter 6</a></h2>
<p>This chapter explains ba bla bla</p>
<script>
document.write("Return to anchor: ");
document.write(document.getElementById("c6").name);
</script>

</body>
</html>

The output of the above example is:

Return anchor: C6

Try it yourself »


Anchor 对象参考手册Anchor Object Other Extensions