1

Here is my html code:

 <a href="http://www.google.com/" target="_blank">Google</a> 

I need a jquery code to find Google.com and change it to Yahoo.com.

For example, if you click on the Google text then yahoo.com will open in your browser.

Is it possible to use jquery to find all Google texts in current page and replace them with Yahoo?

ataravati
  • 8,891
  • 9
  • 57
  • 89
Amin
  • 414
  • 1
  • 11
  • 23
  • Duplicate of this: http://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery – ataravati Aug 24 '13 at 21:51

3 Answers3

2

This should do the trick:

$('a[href*="google"]').each(function() {
  $(this).attr('href', $(this).attr('href').replace(/google/i, 'yahoo');
});

Aside from that I see no reason sinister enough to actually use this...

boxmein
  • 865
  • 7
  • 19
  • Ok Pls check this link: (http://www.malayatourism.com/google.php) so, I added your code inside, but when you click on google, still google website will open in browser. I want when I click on google text, then yahoo website will open . – Amin Aug 24 '13 at 22:07
  • The problem is that you have in fact not included jQuery in the document. Add this tag before my script: `` – boxmein Aug 24 '13 at 22:12
  • Mark the solution too please :) – boxmein Aug 24 '13 at 22:26
0

This is a strange question:

$('a[href*="google"]').each( function (i) {
  $(this).attr("src","http://yahoo.com")
});
Jeffpowrs
  • 4,430
  • 4
  • 30
  • 49
0

Code Example:

$('a[href*="google.com"]').each( function (i) {
  $(this).attr("href","http://yahoo.com");
});

Fiddle: http://jsfiddle.net/f4WmR/


Useful links

JQuery Selectors

JQuery .attr() Documentation

  • Ok Pls check this link: (malayatourism.com/google.php) so, I added your code inside, but when you click on google, still google website will open in browser. I want when I click on google text, then yahoo website will open . – Amin Aug 24 '13 at 22:12