linkObject.typeは、link要素(リンク要素)のtype属性の値を取得、もしくは、設定するプロパティ。
type属性には、リンク先ドキュメントのMIMEタイプを指定することができる。
構文
取得
var $type = $linkElementReference.type;
戻り値
link要素(リンク要素)のtype属性の値。
設定
$linkElementReference.type = MIMEType;
- MIMEType
- リンク先のドキュメントのMIMEタイプを指定。
- 例:
			- text/html:HTML
- text/xml:XML
- text/css:CSS
- text/plain:テキスト
- image/png:PNG
- image/jpeg:JPEG
- image/gif:GIF
- audio/mpeg:MP3
- video/mpeg:MPEG
- video/mp4:MP4
- application/pdf:PDF
- application/x-shockwave-flash:Flash
 
サンプル
変更後のtype属性の値:
サンプルの動作について
- 「text/html」ボタンをクリックすると、「link要素サンプル」のtype属性値を「text/html」に設定する。「変更後のtypeプロパティの値:」の右横に「text/html」と表示する。
- 「text/plain」ボタンをクリックすると、「link要素サンプル」のtype属性値を「text/plain」に設定する。「変更後のtypeプロパティの値:」の右横に「text/plain」と表示する。
- 「text/css」ボタンをクリックすると、「link要素サンプル」のtype属性値を「text/css」に設定する。「変更後のtypeプロパティの値:」の右横に「text/css」と表示する。
サンプルのソースコード
JavaScript
<script type="text/javascript">
function setType( $type ) {
var $elementReference = document.getElementById( "sampleLink" );
$elementReference.type = $type;
var $type = $elementReference.type;
document.getElementById( "sampleOutput" ).innerHTML = $type;
}
</script>
function setType( $type ) {
var $elementReference = document.getElementById( "sampleLink" );
$elementReference.type = $type;
var $type = $elementReference.type;
document.getElementById( "sampleOutput" ).innerHTML = $type;
}
</script>
HTML
<button onclick="setType('text/html');">text/html</button>
<button onclick="setType('text/plain');">text/plain</button>
<button onclick="setType('text/css');">text/css</button>
<p>変更後のtype属性の値:<span id="sampleOutput"></span></p>
<link id="sampleLink" href="sample.html" type="text/html" />
<button onclick="setType('text/plain');">text/plain</button>
<button onclick="setType('text/css');">text/css</button>
<p>変更後のtype属性の値:<span id="sampleOutput"></span></p>
<link id="sampleLink" href="sample.html" type="text/html" />
このサンプルでは、body要素内にlink要素を書いてしまってるが、本来は、head要素内に書く。