Javascript DOM HTML Anchor type Property get

Introduction

Return the MIME type of a specific link:

var x = document.getElementById("myAnchor").type;

Click the button to display the value of the type attribute of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" 
      type="text/html" 
      href="https://www.java2s.com/">Examples</a></p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w w w  .ja v a 2s  .c  o  m
  var x = document.getElementById("myAnchor").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The type property sets or gets the value of the type attribute of a link.

The type attribute sets the MIME type of the target URL.




PreviousNext

Related