How to add a href link with jquery?

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

This is the code that I have that doesn't seem to work.

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

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

+3
source share
1 answer

here is how to do it

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

All Articles