How to set the href value of an anchor tag in JavaScript?

To set the href value of an anchor tag in JavaScript, do this: a.setAttribute('href', value).

For example, if this is your anchor:

<a id="my-link">My Link</a>

Then you can set the href value to, say, https://whaa.dev with this JavaScript:

document.getElementById('my-link').setAttribute('href', 'https://whaa.dev');