To change the href for a hyperlink using jQuery you can use the following snippet.
The following example will change every href to https://codesnippets.fesslersoft.de.

Sample jQuery

$("a").attr("href", "https://codesnippets.fesslersoft.de/")

if you want to change every href pointing to https://codesnippets.fesslersoft.de with a href pointing to https://codesnippets.fesslersoft.de/change-the-href-for-a-hyperlink you can use the following snippet.

Sample jQuery

$("a[href^='https://codesnippets.fesslersoft.de/']")
   .each(function()
   { 
      this.href = this.href.replace("https://codesnippets.fesslersoft.de/", "https://codesnippets.fesslersoft.de/change-the-href-for-a-hyperlink");
   });

2 thought on “How to change the href for a hyperlink using jQuery”

Leave a Reply