Reputation: 61
I have some "a" tags in div. I have to change part of the href. For example: http://jsfiddle.net/A6z88/, I have to change only 'foo' in the href with 'asd'. Thanks a lot and sorry for my english :D
Upvotes: 2
Views: 1623
Reputation: 22438
The most elegant way with the fewest function calls is:
$('a').attr('href', function(i, val){
return val.replace('foo', 'asd');
});
Upvotes: 0
Reputation: 76870
I'd do
$('#links a').each(function(){
this.href = this.href.replace('/foo/', '/asd/');
});
Upvotes: 2
Reputation: 26699
$('div a').each(function(){
$(this).attr('href', $(this).attr('href').replace('foo', 'asd'));
});
Upvotes: 4