Danny Garcia
Danny Garcia

Reputation: 841

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 little control to how these pagination links are generated.

Upvotes: 0

Views: 670

Answers (3)

cambraca
cambraca

Reputation: 27835

$('#pagination a').attr('href', function() {
  return this.href + '?some=blah';
});

Look at it working here.

Edited as per elusive's input in the comments.

Upvotes: 3

jwueller
jwueller

Reputation: 30996

This should work for you:

$('#pagination a').each(function () {
    this.href += '?some=blah';
});

Change #pagination a to whatever selector you need.

Upvotes: 1

Hamish
Hamish

Reputation: 23326

Quick and dirty:

$('#pagination li a').each(function() {
    this.href += '?some=blah';
});

Upvotes: 1

Related Questions