HTML DOM Anchor download Property


The HTML DOM download property is used to set or return the value of the download attribute of a link.

Following is the syntax to set the download property −

anchorObject.download = file

Above, file represents the file name you can set for the file to be downloaded. The actual extension will get suffixed.

Following is the syntax to return the download property: anchorObject.download

Let us now see an example to implement the DOM Anchor download property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>ReactJS</h2>
<a id="myid" href="http://www.tutorialspoint.com/images/reactjs.png" download="Learn
ReactJS">
<img src="http://www.tutorialspoint.com/images/reactjs.png" alt="ReactJS" width="200"
height="200"></a>
<button onclick="display()">Display the value</button>
<p id="demo"></p>
<script>
   function display() {
      var val = document.getElementById("myid").download;
   document.getElementById("demo").innerHTML = val;
   }
</script>
</body>
</html>

Output

Now, click on the button to display the value −

Updated on: 30-Jul-2019

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements