0

I have a loop in which I make a table like following:

for (k in data['rd']) {
    tableData += '<table>... //skipped code
        <tr>
                            .
                            .
                            .
            <td class="'+data['rd']['time']+'"></td>
        </tr>
    </table>';


    //I want to create a count up on all of the above TD with following
    //FormatDate function formats the data into format mm/dd/yyyy hh:mm

    document.body.addEventListener("DOMNodeInserted", function(event) {
        var elementJustAdded = $('.rd'+k);
        elementJustAdded.countdown({since: new Date(formatDate(data['rd'][k]['ordered'])), until: new Date()})
    }, false);
}
 //Then I attach above "tableData" variable to my div.

Above brief code results in the count down timer only applied to the last TD. So for example if there was say 50 records then only 50th row would display the timer.

Can someone please help me so that I can attach count-up timer to each and every row in the table for given TD.

Sahil
  • 1,959
  • 6
  • 24
  • 44
  • 1
    I think if you would restructure you're code you could use the like provided by @Quentin to do what you need. – ars265 Sep 03 '13 at 15:31
  • 1
    Instead of appending to a variable, if you actually append the content you'll be able to access the element and attach the listener. – Matthew Riches Sep 03 '13 at 15:35

0 Answers0