Anchor download Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


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

Property Values

filename Set text to be used as the filename. If omitted, the original filename is used.

Return Value

A String, representing the name of the downloaded file

The following code shows how to Display the value of the download attribute of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<a id="myAnchor" href="" download="myDownloadFileName">
<img border="0" src="" alt="alt message" width="104" height="142"></a>

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

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

function myFunction() {//from   w w  w  .j a v a  2  s . com
    var x = document.getElementById("myAnchor").download;
    document.getElementById("demo").innerHTML = x;


Related Tutorials