I have this problem in using the jQuery's .each () function. I want to sort the rows and columns of a table with me, which I am trying to do by adding 'Row' and 'Colonel' properties to my 'TD' tag.
Basically my code looks at each (function (TD_index) {$ (this) .attr ({'line': tr_index, 'col': td_index,});});});
But it gives me the following output:
& lt; Td line = "6" col = "0" & gt; & Lt; / Td> & Lt; Td row = "6" col = "1" & gt; & Lt; / Td> & Lt; Td line = "6" col = "2" & gt; & Lt; / Td> & Lt; Td row = "6" col = "3" & gt; & Lt; / Td> & Lt; Td row = "6" col = "4" & gt; & Lt; / Td> & Lt; Td row = "6" col = "5" & gt; & Lt; / Td> & Lt; Td row = "6" col = "6" & gt; & Lt; / Td> Line attribute output 6 on each single 'TD' tag. This means that the first .each () loop is executed before any other seconds. The former () loop is removed?
Any ideas how can I change it so that I have something like this:
& Lt; Td line = "0" col = "1" & gt; & Lt; / Td> & Lt; Td line = "0" col = "2" & gt; & Lt; / Td> & Lt; Td line = "1" col = "0" & gt; & Lt; / Td> & Lt; Td line = "1" col = "1" & gt; & Lt; / Td> & Lt; Td line = "1" col = "2" & gt; & Lt; / Td> & Lt; Td line = "2" col = "0" & gt; & Lt; / Td> etc ...
If anyone has a solution to this problem for me, then I will be thankful because I can not wrap my head around him. .
Try it
$ ('tr'). Each (function (idx_row) {$ (this). Child (). (Function (idx_col) {$ (this) .attr ({'row': idx_row, 'col': idx_col})}}}});
Comments
Post a Comment