Wednesday 15 February 2012

datejs - jquery: iterate through tables comparing hardcoded date against Date.today() then dropping dates<today -


Thanks to everyone for considering my new issue I used jQuery to iterate through a table I am capturing and capturing all hardcod dates in an array. I compare date to those dates date (); If using the .isAfter () function, if the date of the hardcoded is in the past, then its Get CSS ("Display", "None");

  & lt; Table & gt; & Lt; Html & gt; & Lt; Table & gt; & Lt; Tr class = "gig" & gt; & Lt; Td square = "gigDate" & gt; 27 March 2013 & lt; / Td> & Lt; Td> Salon & lt; / Td> & Lt; Td> Atlanta, GA & lt; / Td> & Lt; Td> $ 20 (2 pass) & lt; / Td> & Lt; Td> Button tix & lt; Td> & Lt; / TR & gt; & Lt; Tr class = "gig" & gt; & Lt; Td square = "gigDate" & gt; ... date2 .. & lt; / Td> & Lt; / Tr & gt; & Lt; Tr class = "gig" & gt; & Lt; Td square = "gigDate" & gt; ... Date 3 .. & lt; / Td> & Lt; / Tr & gt; & Lt; Tr class = "gig" & gt; & Lt; Td square = "gigDate" & gt; ... date4 ect .. & lt; / Td> & Lt; / Tr & gt; & Lt; / Table & gt; & Lt; Script type = "text / javascript" & gt; Create $ ("document") (function () {ARR to hold {var stringDate = []; // elements now = dateToday (); // create current date $ ('.gigDate'). (I, e) {// array string data is added to date ($ (e) .text ());}); (var y = 0; y & lt; stringDate.length; y ++) {var SingleDet = Date. PRSE (StringDit [Y]); // compare to purse to milliseconds er = now. Enter the same date (// date) if compare (compare) {$ ('.gig '). CSS ("display", "none"); // hide & lt; tr class = "gig"> if in past}}}); & Lt; / Script & gt;   

The loop logic seems to work properly, but if (statement) that adds to the performance of the style: no one is odd, any help would be welcomed.

When you try to hide a line, you can hide all of them - $ ('.gig') selects all the rows, not that you think so.

Take your logic inside the loop where you test the date. In roughly this way (I am changing my code as much as possible, it is still not working, it has not checked):

  var now = date.today (); // Create current date $ ('.gigDate') Every (function (i, e) {// adds a hardcode date to turn on the circled var current = ($ (e) .text ()); var singleDate = Date.parse current); // pars for mseconsages = compare now = now Later (single date); // Compare today's date if (compare) {// We want to hide TD's guardian, TD: $ (e) No (). CSS ("Display", "None"); // Hide & lt; Tr class = "gig" & gt; // if first}});    

No comments:

Post a Comment