ShanghaiD
asked on
jquery each loop to add data() to each td column
I have programatically created a table by constructing the HTML code and then appending it to the table body: $('#tsTable').find('tbody' ).append(s trHTML.joi n(''));
I am now trying to loop through every td of every tr and add the text() of each td as a data() value for each of those tds. (I will actually manipulate the text() first, but for this illustration I show simplifiied code for a straight copy of each text() to each data() item).
his is the code I am using (without success):
I am now trying to loop through every td of every tr and add the text() of each td as a data() value for each of those tds. (I will actually manipulate the text() first, but for this illustration I show simplifiied code for a straight copy of each text() to each data() item).
his is the code I am using (without success):
$.each($('#tsTable tbody tr'), function(row) {
$.each([1,2,3,4,5,6,7,8], function(n,v){
var theData = $(this)('td:nth-child(v)').text();
$('#tsTable tbody tr td:nth-child(v)').data('val',theData);
});
});
Any suggestions to get the data() from each td.text() would be appreciated!
Change
var theData = $(this)('td:nth-child(v)').text();
tovar theData = $('td:nth-child(v)', this).text();
ORvar theData = $(this).find('td:nth-child(v)').text();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the most elegant and simplest syntax for what I am trying to do.
ASKER
I can use this technique when I programatically create the strHTML.
However, I would still like to understand how I could make my above jquery code work correctly.