Here is my HTML structure:
<table id="items" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td> </td>
<td>Name</td>
<td>Description</td>
<td>Location</td>
</tr>
<tr>
<td>
<button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-plus"></span>
</button>
</td>
<td><input type="text" id="addName"></td>
<td><input type="text" id="addDescription"></td>
<td></td>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
</table>
And here is my jQuery code:
function getTable(){
var args = new Object();
args.op = "getTable";
$.post("./service.php", args , function(data)
{
var dataObj = JSON.parse(data);
for(var i = 0; i<dataObj.length; i++){
$('table#items tbody').append("<tr class=\"items_tr\" id=\"item"+dataObj[i].sn+"\"><td>"+dataObj[i].sn+"</td><td>"+dataObj[i].name+"</td><td>"+dataObj[i].description+"</td><td>"+dataObj[i].belonged+"</td></tr>");
}
});
}
getTable();
$('tbody').children("tr").hide();
$("tbody tr").hide();
$("tr.items_tr").hide();
The Last 3 statements do not work at all.
Cannot select created <tr>s.
Why and how can I select them?
$("tr").hide();
This one hides only <tr>s inside <thead>, things that have already been created.
more questions - How about .each() function?
I want to bind a click event on each td tag, and I failed again..
How to iterate all new added <td>s?