I don't know what I am doing wrong with changing href attribute in link from ?page to &page. It stays on ?page. Thank you for any advice.
Jquery:
var article_pagination_change = function(){
$('pagination a').each(function(){
$(this).href.replace('?page','&page');
});
}
article_pagination_change();
HTML:
<div id="pagination80" class="pagination" style="">
<a class="first" data-action="first" href="?page=1"><<</a>
<a class="previous" data-action="previous" href="?page=1"><</a>
<input class="pag_input_80" type="text" value="1 of 12" data-max-page="12" readonly="readonly">
<a class="next" data-action="next" href="?page=2">></a>
<a class="last" data-action="last" href="?page=12">>></a>
</div>
I don't know what I am doing wrong with changing href attribute in link from ?page to &page. It stays on ?page. Thank you for any advice.
Jquery:
var article_pagination_change = function(){
$('pagination a').each(function(){
$(this).href.replace('?page','&page');
});
}
article_pagination_change();
HTML:
<div id="pagination80" class="pagination" style="">
<a class="first" data-action="first" href="?page=1"><<</a>
<a class="previous" data-action="previous" href="?page=1"><</a>
<input class="pag_input_80" type="text" value="1 of 12" data-max-page="12" readonly="readonly">
<a class="next" data-action="next" href="?page=2">></a>
<a class="last" data-action="last" href="?page=12">>></a>
</div>
Share
Improve this question
asked Mar 28, 2014 at 22:57
user3342042user3342042
2411 gold badge7 silver badges20 bronze badges
1
- that dot is very small I can't see it :) thank you – user3342042 Commented Mar 28, 2014 at 23:01
2 Answers
Reset to default 5You need to actually set the attribute:
var article_pagination_change = function(){
$('.pagination a').each(function(){
var newurl = $(this).attr('href').replace('?page','&page');
$(this).attr('href', newurl);
});
}
article_pagination_change();
Note that I added the .
before pagination
and am using attr('href')
instead of just href
.
Here's a working jsFiddle.
If you don't mind changing your code a bit more, you can try this simpler approach:
var article_pagination_change = function(){
$('.pagination a').attr('href',function(index,attr){
return attr.replace('?','&');
});
}
article_pagination_change();
You don't really need the .each()
nor replacing ?page
with &page
unless you had extra ?
s on your href
s...
Sample JSFiddle