0

I want to change belo url using javascript

From:

<a class='button' href="#" target="_blank" id="download_link" style="display: none;"><i class='icon download'></i>Download Now</a>

To

<a class='button' href="https://google.com" target="_blank" id="download_link" style="display: none;"><i class='icon download'></i>Download Now</a>

My code is

<a class='button' href="#" target="_blank" id="download_link" style="display: none;"><i class='icon download'></i>Download Now</a>
<script type="application/javascript">
 var tURL = "https://google.com"
 var download_link = document.getElementById("download_link");
 download_link.innerHTML.replace("#", tURL);

where I do mistake please correct this. I know it is easy to use hyper link in html. but I want to replace urls using javascript

  • Does this answer your question? [How to change the href attribute for a hyperlink using jQuery](https://stackoverflow.com/questions/179713/how-to-change-the-href-attribute-for-a-hyperlink-using-jquery) – Uttam Nath Jun 18 '22 at 08:28

1 Answers1

2
var download_link = document.getElementById("download_link");
download_link.href = tURL;

or

var download_link = document.getElementById("download_link");
download_link.setAttribute('href', tURL);
User456
  • 1,216
  • 4
  • 15