Read table contents
by ChrisStanyon
HTML
<table class="mytable">
<tr>
<td>01</td>
<td>price01</td>
<td>location01</td>
</tr>
<tr>
<td>02</td>
<td>price02</td>
<td>location02</td>
</tr>
</table>
<button id="click">Click Me</button>
<div id="01" class="place">This is 01</div>
<div id="02" class="place">This is 02</div>
CSS
td { border: 1px solid green; padding: 5px; }
button { margin: 5px 0px; }
.place { border: 1px solid blue; padding: 10px; margin: 5px 0px; }
JavaScript
$('#click').click(function() {
var resultStr = "";
$(".mytable").find("td:nth-child(1)").each(function () {
//alert($(this).text());
//resultStr +=$(this).text();
var ID = $(this).text();
$("#" + ID).append("done " + ID);
});
//$('.place').each(function () {
// var appendID = $(this).attr('id');
// if ($(appendID) == $(resultStr)) {
// $('.place').append(resultStr).html();
//}
// alert(resultStr);
//
// });
// $('.place').each(function () {
// var appendID = $(this).attr('id');
// if ($(appendID) == $(resultStr)) {
// $('.place').append(resultStr).html();
// }
// });
} )