changing the attribute href by leveraging javascript

When setting the href, include the protocol, eg http or https:

const anchors = document.querySelectorAll('a');
function changeHyperlink() {
  for (var i = 0; i < anchors.length; i++) {
    anchors[i].href = "https://www.drift-demo.com";
  }
}

changeHyperlink();
<a>some anchor</a>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top