Append string to child link URLs
What's the best way to append a string to the end of links in a list with Javascript? From:
<div id="pagination">
<ul>
<li><a href="http://site.com/P1/">Page 1</a></li>
<li><a href="http://site.com/P2/">Page 2</a></li>
</ul>
</div>
to
<div id="pagination">
<ul>
<li><a href="http://site.com/P1/?some=blah">Page 1</a></li>
<li><a href="http://site.com/P2/?some=blah">Page 2</a></li>
</ul>
</div>
ExpressionEngine gives litt开发者_如何学Gole control to how these pagination links are generated.
$('#pagination a').attr('href', function() {
return this.href + '?some=blah';
});
Look at it working here.
Edited as per elusive
's input in the comments.
Quick and dirty:
$('#pagination li a').each(function() {
this.href += '?some=blah';
});
This should work for you:
$('#pagination a').each(function () {
this.href += '?some=blah';
});
Change #pagination a
to whatever selector you need.
精彩评论