Javascript DOM HTML Anchor download Property set

Introduction

Change the value of the download attribute of a link:

document.getElementById("myAnchor").download = "newValue";

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

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. co  m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("myAnchor").download = "newValue";
  document.getElementById("demo").innerHTML = "download attribute changed";
}
</script>

</body>
</html>



PreviousNext

Related