Reputation: 33
I'm new to jQuery and I'm trying to replace numerous link by another one, but I can't seem to find why it doesn't, could you help me please.
Code:
First attempt:
jQuery(document).ready(function() {
$("a").each(function() {
newUrl += $(this).href+ textOfNew + " ";
this.href = this.href.replace((this.href), newUrl);
});
});
Second attempt:
jQuery(document).ready(function() {
$("a").each(function() {
$("$(this).href").val(function(i, val) {
var newUrl = "test" ;
return = $(this).href.replace($(this).href, newUrl);
});
});
});
Upvotes: 0
Views: 299
Reputation: 318192
jQuery(function($) {
$("a").attr('href', function(i, href) {
return href + '/test';
});
});
Upvotes: 2
Reputation: 6878
$("a").each(function() {
newUrl += $(this).attr("href") + textOfNew + " ";
$(this).attr("href", newUrl);
});
Upvotes: 0
Reputation: 40318
try this
$("a").each(function() {
var newUrl = $(this).attr('href')+ textOfNew + " ";
$(this).attr('href',newUrl);
});
Upvotes: 2