-1

Here is my HTML

<div class="nav-wrapper">
<nav>
<ul>
<li><a href="https://mytestsite.com/search/label/Technology?m=1" rel="tag"></a></li>
<li><a href="https://mytestsite.com/search/label/Science?m=1" rel="tag"></a></li>
<li><a href="https://mytestsite.com/search/label/Invention?m=1" rel="tag"></a></li>
<li><a href="https://mytestsite.com/search/label/History?m=1" rel="tag"></a></li>
<li><a href="https://mytestsite.com/search/label/Humanity?m=1" rel="tag"></a></li>
</ul>
</nav>
</div>

I want to remove ?m=1 and add &max-results=7&m=1. Can someone please help me with this?

Aarnivep
  • 1
  • 2
  • [Google it](https://www.google.lv/search?q=change+href+parameter+jquery&oq=edit+href+para&aqs=chrome.1.69i57j0l4.5940j0j4&sourceid=chrome&ie=UTF-8) – Mike B Sep 14 '16 at 12:14

3 Answers3

2

You can use .attr(attributeName, function)

$('nav-wrapper a').attr('href', function(_, value){
    return value.replace('m=1', 'max-results=7&m=1');
});
Satpal
  • 132,252
  • 13
  • 159
  • 168
1

try replace()

href = $('a').attr('href')

$('a').attr('href', href.replace('m=1', 'max-results=7&m=1') ) 
Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24
0

All the above answers are correct. But simple string concate will also work for you.

href = $('a').attr('href');
$('a').attr('href', href+'&max-results=7'); 
Ish
  • 2,085
  • 3
  • 21
  • 38