Search code examples
jqueryreplacehrefattr

jQuery replace href URL on PHP page


I am trying to achieve something that should be easy in theory

I have a php (zen-cart) generated page

I want to change 1 URL to another one, using jQuery.

So I would load the jQuery in the head section, then at the bottom of my document I would stick:

 <script>
    $(document).ready(function() {
       $("a[href='http://myurl']").attr('href', 'http://anotherURL')
    });
 </script>

Yet, this is not working... what am i doing wrong?


Solution

  • $(document).ready(function() { $("a[href*='http://myurl']").attr('href', 'http://anotherURL'); });