name property (a)
Sets or retrieves the name of a target anchor.
Named anchors can be the targets of source anchors.
If the href property of an anchor is set to the '#targetName' value, where the targetName is the value of an anchor's name property, then the first anchor (source) refers to the second anchor (target anchor).
Clicking on the source anchor scrolls the target anchor into the visible area of the document.
See the page for the href property or Example 1 for further details.
The name property can be used as a reference on the client side.
You can get an array of elements that have the same name with the getElementsByName method.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: name |
Possible values:
String that sets or retrieves the name of the target anchor.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the name attribute:
|
||||
Table of contents: <ul> <li><a href="#section1">1. Section</a></li> <li><a href="#section2">2. Section</a></li> <li><a href="#section3">3. Section</a></li> </ul> <b><a name="section1">1. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> <b><a name="section2">2. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> <b><a name="section3">3. Section</a></b><br /> First line in the section.<br />...<br />...<br />...<br /> Last line in the section.<br /><br /> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the name property and the getElementsByName method:
|
||||
<head> <script type="text/javascript"> function CollectByName () { var tags = document.getElementsByName ("myAnchor"); var count = tags.length; alert ("There are " + count + " element(s) with the specified name attribute: " + tags[0].name); } </script> </head> <body> <a name="myAnchor">The first anchor element</a> <a name="myAnchor">The second anchor element</a> <br /> <button onclick="CollectByName ();">Collect elements by name</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
Related pages:
External links:
name (MSDN)
general elements name attribute (Mozilla Developer Center)
name (Safari Reference Library)
name (W3C)
general elements name attribute (Mozilla Developer Center)
name (Safari Reference Library)
name (W3C)
User Contributed Comments