How do I change the content of the cell containing the \'c\' letter in the HTML sample using jQuery?
相关标签: 6条回答 眼角桃花 2020-12-29 03:48 You can use CSS selectors. Depending on how you get that td, you can either give it an id: <td id='cell'>c</td> and then use: $("#cell").text("text"); Or traverse to the third cell of the first row of table_header, etc. 0 讨论(0) 发布评论: 提交评论 加载中... 爱一瞬间的悲伤 2020-12-29 03:49 I wanted to change the column value in a specific row. Thanks to above answers and after some serching able to come up with below, var dataTable = $("#yourtableid"); var rowNumber = 0; var columnNumber= 2; dataTable[0].rows[rowNumber].cells[columnNumber].innerHTML = 'New Content'; 0 讨论(0) 发布评论: 提交评论 加载中... 粉色の甜心 2020-12-29 03:52 $("td:contains('c')").html("new"); or, more precisely $("#table_headers td:contains('c')").html("new"); and maybe for reuse you could create a function to call function ReplaceCellContent(find, replace) { $("#table_headers td:contains('" + find + "')").html(replace); } 0 讨论(0) 发布评论: 提交评论 加载中... [愿得一人] 2020-12-29 03:54 You can do this : <table id="table_header"> <tr> <td contenteditable="true">a</td> <td contenteditable="true">b</td> <td contenteditable="true">c</td> </tr> </table> 0 讨论(0) 发布评论: 提交评论 加载中... 感情败类 2020-12-29 04:07 i was looking for changing second row html and you can do cascading selector $('#tbox1 tr:nth-child(2) td').html(11111) 0 讨论(0) 发布评论: 提交评论 加载中... 余生分开走 2020-12-29 04:09 Using eq() you can target the third cell in the table: $('#table_header td').eq(2).html('new content'); If you wanted to target every third cell in each row, use the nth-child-selector: $('#table_header td:nth-child(3)').html('new content'); 0 讨论(0) 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复 热议问题
You can use CSS selectors.
Depending on how you get that td, you can either give it an id:
<td id='cell'>c</td>
and then use:
$("#cell").text("text");
Or traverse to the third cell of the first row of table_header, etc.
I wanted to change the column value in a specific row. Thanks to above answers and after some serching able to come up with below,
var dataTable = $("#yourtableid"); var rowNumber = 0; var columnNumber= 2; dataTable[0].rows[rowNumber].cells[columnNumber].innerHTML = 'New Content';
$("td:contains('c')").html("new");
or, more precisely $("#table_headers td:contains('c')").html("new");
$("#table_headers td:contains('c')").html("new");
and maybe for reuse you could create a function to call
function ReplaceCellContent(find, replace) { $("#table_headers td:contains('" + find + "')").html(replace); }
You can do this :
<table id="table_header"> <tr> <td contenteditable="true">a</td> <td contenteditable="true">b</td> <td contenteditable="true">c</td> </tr> </table>
i was looking for changing second row html and you can do cascading selector
$('#tbox1 tr:nth-child(2) td').html(11111)
Using eq() you can target the third cell in the table:
$('#table_header td').eq(2).html('new content');
If you wanted to target every third cell in each row, use the nth-child-selector:
$('#table_header td:nth-child(3)').html('new content');