Reputation: 7332
Having htmls like this,
<a class="testDiv" href="/link1"></a>
<a class="testDiv" href="/link2"></a>
I'm trying to append ?param1=2
to the href
attributes of all <a>
tags.
So that it should look like,
<a class="testDiv" href="/link1?param1=2"></a>
<a class="testDiv" href="/link2?param1=2"></a>
Something like this,
$(".testDiv").attr('href').append("?param1=2");
Is there any possible way for this?
Upvotes: 1
Views: 45
Reputation: 208032
$(".testDiv").attr('href', function (_, currentHref) {
return currentHref +"?param1=2"
});
Upvotes: 4