I want to print a value in each table cell after creating it dynamically.
<table id="MapDetails"><tr> <td/><td/><td/><td/> var colIndex = 4; foreach(MapDetail geMapDetail in Model.mapDetails) { <td class="test"> <script>{getPosition(@geResult.assessmentId, @colIndex, @rowIndex, '@geResult.ResultValue');}</script> </td> colIndex++; } </tr></table> My script
THIS DOES NOT WORK
function getPosition(id, colIndex, rowIndex, resultValue) { var element = '#' + id; var cell = $('#MapDetails tr:eq(' + rowIndex + ') td:eq(' + colIndex + ')'); if($(element).index() == colIndex){ cell.innerHTML = resultValue; } } THIS WORKS ONLY FOR THE FIRST CELL
function getPosition(id, colIndex, rowIndex, resultValue) { var element = '#' + id; var cell = $(".test").closest('tr').find('td').get(colIndex); if($(element).index() == colIndex){ cell.innerHTML = resultValue; } }
tds don't have any classname or id in the given markup.