Dave
Dave

Reputation: 9167

How to append a link's HREF with jquery?

I want to change all links containing "foobar.com/?" to ad "&t=test" ("foobar.com/?&t=test") with jquery.

This is the code I have that does not seem to work. ->

$('a[href*="foobar.com/?"]').attr(href).append('&t=test');

What is wrong with my code? Or what is a more proper way to change all the links?

Upvotes: 3

Views: 3556

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196306

this is how to do it

$('a[href*="foobar.com/?"]').each(function(){
  this.href += '&t=test';
});

Upvotes: 7

Related Questions