Jquery: most efficient way to get and store ids from 100 + td elements?

So, I have about six such calendars per page, which is about 180 td (1 for each date):

http://i44.tinypic.com/eiwphl.jpg

each td has an ID equal to that time of day. the dates I want are red (class .booked

).

So I need the fastest way to "serialize" IDs for items, td.booked

on td.booked

, any ideas?

+2


a source to share


3 answers


You can get an array of IDs using .map()

for example:

var ids = $("td.booked").map(function() { return this.id; }).get();

      



This will result in an array like this:

["id1", "id2", "id3", ... ]

      

+4


a source


What exactly do you mean by serialization?



If they are tagged on the client, then the fastest way to collect links to them is to collect them as they are tagged. Then you already point to them when you need it, and no retroactive requests are required.

+2


a source


How about this:

var str = '';

$(function(){
  $('td.booked').each(function(index){
     str += '&td' + index + "=" + encodeURIComponent($(this).text());
  });
});

alert(str);

      

0


a source







All Articles