Javascript Reference - HTML DOM Anchor type Property








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.

Browser Support

type Yes Yes Yes Yes Yes

Syntax

Return the type property:

var v = anchorObject.type 

Set the type property:

anchorObject.type = MIME-type;




Property Values

Value Description
MIME-type Set the MIME type of the linked document.

Return Value

A String representing the MIME type of the linked document.

Example

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:





Example 2

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: