Change the href for a hyperlink using jQuery

For example, You can change the href for a hyperlink using jQuery...

Demo

Example.com
Google.com
Wikipedia.org

HTML

<a href="http://example.com" target="_blank">Example.com</a>
<br>
<a href="http://google.com" target="_blank">Google.com</a>
<br>
<a href="http://wikipedia.org" target="_blank">Wikipedia.org</a> 
</section>

Jquery

$(function(){
    var anchors = document.querySelectorAll('a');
    Array.prototype.forEach.call(anchors, function (element, index) {
        element.href = "http://www.htmllion.com";
    });
})
  • Share
  • Copyright 2016 by WebiBeris.com. All Rights Reserved.