-3

How can you change the href for a hyperlink using jQuery?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

        $("a").each(function(){

         var href = $(this).attr('href');
         alert(href);
         var reg =href+'hiii' ;
          alert(reg);

         $(this).attr("href", reg);
            alert($(this).text())
        });

    });
</script>

<button>Alert the value of each list item</button>
<ul>
<a href="yuyuyuyuyuy"><p>If you click on me, I will disappear.</p></a>
<a href="ioooo"><p>If you click on me, I will disappear.</p></a>
</ul>

this is how u can chenge and even edit the link work for affiliate link edit on site remove jquery alart

1 Answers1

1

This is very basic google search usage.

The answer would be: 1. Set an id to that tag, like this

<a id="my_link"></a>

Then change it using jquery:

$("#my_link").attr("href", "your_link")
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Marwan
  • 388
  • 2
  • 11