JavaScript入門講座

Home > anchorオブジェクト > nameプロパティ

nameプロパティ

anchorオブジェクトのnameプロパティはアンカー名を返します。ページのアンカー情報は配列で格納されているのでIndex番号を指定してプロパティの値を取得します。

書式document.anchors[index番号].name
ブラウザInternet ExplorerFireFoxChromeSafariOpera
アンカー名
使用例現在のページのアンカー名を表示する。

<html>
<head>
<title>JavaScript anchor name</title>
<script type="text/javascript">
function dispAnchorName(){

	for(var i=0 ; i < document.anchors.length ; i++){
		alert('アンカー名:' + document.anchors[i].name);	
	}

}
</script>
</head>
<body>
<a name="#anchor1">アンカー1</a><br>
<a name="#anchor2">アンカー2</a><br>
<a name="#anchor3">アンカー3</a><br>
<form name="fm">
アンカー名を表示<br>
<input type="button" value="確認" onClick="dispAnchorName()">
</form>
</body>
</html>
						
関連メンバ
lengthアンカー数