Javascript DOM HTML Anchor download Property get

Introduction

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

It sets the file name for the download.

We do not need to set file extension, the browser will set the correct file extension.

If omitted, the original filename is used.

download property return a String representing the name of the downloaded file.

The download attribute can download the image on click.

Click button to display the value of the download attribute of the image link.

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<a id="myAnchor" href="image1.png" download="flag">
   <img border="0" src="image1.png" alt="java2s.com">
</a>//from   w ww  . j a  v  a 2  s.  com
<button onclick="myFunction()">Test</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("myAnchor").download;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related