I have a very specific issue that I need help with. On my website, users can select the number of results they want to see displayed. I created buttons and a span element to show the currently selected amount. Now, I am trying to implement an ajax request for this functionality. I need to figure out how to determine the current selected amount and update the HTML so that it always displays the correct amount. My main question is: How can I identify the current data ID and replace only that specific HTML line when a button is clicked?
This is my current HTML setup:
<div class="pagination">
<span>Show orders</span>
<a href="" data-id="25">25</a>
<span class="active" data-id="50">50</span>
<a href="" data-id="75">75</a>
<a href="" data-id="100">100</a>
<a href="" data-id="125">125</a>
<a href="" data-id="150">150</a>
<a href="" data-id="1000">All</a>
</div>
My JQuery code to retrieve the current selected amount:
var selectedAmount = $( ".pagination" ).find ( ".active" ).data( "id" );
And here is my JQuery event handler to swap out the buttons with the span element upon click:
$('.pagination a').on('click', function(event){
event.preventDefault();
// Replace the old highlighted amount button with an <a href> tag
// Swap the old <a href> tag with the newly "highlighted" span button
});