0
<div class="pagination">
 <a id="1">1</a>
 <a id="2">2</a>
 <a id="3">3</a>
 <a id="4">4</a>
</div>

For each of those pages 1-2-3-4 I want to replace their values with Date to become something like >

<div class="pagination">
 <a id="1">22 Oct</a>
 <a id="2">23 Oct</a>
 <a id="3">24 Oct</a>
 <a id="4">25 Oct</a>
</div>

I have create an array where to store the dates. And I need to make the script which will replace those values, can some one help me ?

2
  • why don't you just print the dates from the server? why would you waste clients browser resources for something like this? Commented Oct 21, 2011 at 8:47
  • because those dates are coming from Mysql>PHP script and the pagination is generated by JQUERY. I think that the best way is to make such replaceable script. Commented Oct 21, 2011 at 9:02

2 Answers 2

2

Loop through each anchor in the div, and use the .text() method to set the new value.

var array_dates = ["22 Oct", "23 Oct", "24 Oct", "25 Oct"]; //User-defined
$("div.pagination a").each(function(i){
    $(this).text(array_dates[i]);
})
Sign up to request clarification or add additional context in comments.

Comments

1
var arr = ['22 Oct','23 Oct','24 Oct','25 Oct',]
$('div.pagination a').html(function(i){
   return arr[i];
})

demo

1 Comment

This work too . I will test which is better your or to the previous user. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.