HTML DOM Anchor download Property

HTMLWeb DevelopmentFront End Technology

<p>The HTML DOM download property is used to set or return the value of the download attribute of a link.</p><p>Following is the syntax to set the download property &minus;</p><pre class="result notranslate"> = file</pre><p>Above, file represents the file name you can set for the file to be downloaded. The actual extension will get suffixed.</p><p>Following is the syntax to return the download property:</p><p>Let us now see an example to implement the DOM Anchor download property &minus;</p><h2>Example</h2><p><a class="demo" href="" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h2&gt;ReactJS&lt;/h2&gt; &lt;a id=&quot;myid&quot; href=&quot;; download=&quot;Learn ReactJS&quot;&gt; &lt;img src=&quot;; alt=&quot;ReactJS&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;&lt;/a&gt; &lt;button onclick=&quot;display()&quot;&gt;Display the value&lt;/button&gt; &lt;p id=&quot;demo&quot;&gt;&lt;/p&gt; &lt;script&gt; &nbsp; &nbsp;function display() { &nbsp; &nbsp; &nbsp; var val = document.getElementById(&quot;myid&quot;).download; &nbsp; &nbsp;document.getElementById(&quot;demo&quot;).innerHTML = val; &nbsp; &nbsp;} &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</pre><h2>Output</h2><p><img src="" class="fr-fic fr-dib" style="width:600px; height:317px; border:1px solid black;" width="600" height="317"></p><p>Now, click on the button to display the value &minus;</p><p><img src="" class="fr-fic fr-dib" style="width:600px; height:329px; border:1px solid black;" width="600" height="329"></p>
Updated on 30-Jul-2019 22:30:26