The type
attribute,
new for the <a> element in HTML5,
sets the MIME type of the target URL in the area.
The type
property sets or gets the
value of the type attribute of a link.
type |
Yes | Yes | Yes | Yes | Yes |
Return the type property:
var v = anchorObject.type
Set the type property:
anchorObject.type = MIME-type;
Value | Description |
---|---|
MIME-type | Set the MIME type of the linked document. |
A String representing the MIME type of the linked document.
The following code shows how to get the MIME type.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . ja va 2 s . co m-->
<p><a id="myAnchor" type="text/html" href="http://www.example.com/">example</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myAnchor").type;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set the type attribute of a link to text/html.
<!DOCTYPE html>
<html>
<body>
<!-- w w w.j a v a2 s. c om-->
<p><a id="myAnchor" href="http://www.example.com">example</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myAnchor").type = "text/html";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: