Reputation: 5757
page = 1;
$('.links').click(function() {
$(this).removeAttr('href');
page = $(this).html();
});
<a href="#" class="links"> 1 </a>
<a href="#" class="links"> 2 </a>
<a href="#" class="links"> 3 </a>
when I click a page number, I want to remove the href attribute. The problem is, if I click pages consecutively, the previous page numbers clicked dont regain their href attribute. How could I do this?
Jsfiddle: http://jsfiddle.net/JGpF9/
Upvotes: 0
Views: 1847
Reputation: 5757
Here's the solution:
$('.links').click(function() {
$('.links').slice(page - 1, page).attr('href', '#');
page = $(this).html();
$('.links').slice(page - 1, page).removeAttr('href');
});
Upvotes: 0
Reputation: 25197
Not the best solution, but still an alright one. This adds the href of '#' back onto the links before removing the current one. If the href's were different then you'd have to resolve this a different way.
$('.links').click(function() {
$('.links').attr('href', '#');
$(this).removeAttr('href');
page = $(this).html();
});
NOTE: I would also add the spaces outside of the anchor tags
Upvotes: 1