Capture click and redirecting is not working

Capture click and redirecting is not working

I want to capture any hyperlink click and redirect them to different host name. So far it's not working...not even the alert is showing. Below is my code so far:

  1.     $('a').click(function(e){
  2.         e.preventDefault();
  3.         var href = $(this).attr('href');
  4.         var url_hash = $(href).text().replace("https://mysite.knowledg.com/help/article/link/", "https://devbox.mysite.com/kb/article/");
  5.         alert(url_hash);
  6.         //redirect the link to commonspot page
  7.         if($(this).attr('target') === '_blank')
  8.         {
  9.             window.location.href = url_hash;
  10.         }
  11.         else{
  12.             window.open(url_hash);
  13.         }
  14.     });