W3Schools.com

Anchor name Property

Anchor Object Reference Anchor Object

Definition and Usage

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

The name attribute specifies the name of an anchor, and is used to create a bookmark inside a document.

Syntax

Set the name property:

anchorObject.name="name"

Return the name property:

anchorObject.name

Value Description
name Specifies the name of the anchor


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The name property is supported in all major browsers.


Example

Example

Return the name of a specific anchor:

<html>
<body>

<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><a id="c3" name="C3">Chapter 3</a></h2>
<p>This chapter explains ba bla bla</p>

<script type="text/javascript">
document.write("Return name of anchor: ");
document.write(document.getElementById("c3").name);
</script>

</body>
</html>

The output of the code above will be:

C3

Try it yourself »


Anchor Object Reference Anchor Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE