Reputation: 17
hi this code expalins to the dynamcically add and deletind the rows, if i select the row ,it sholud be change this background color can please help me thanks
Dynamic Creation
$(document).ready(function() {
$("<table class='table1' border='1'></table>").appendTo(".div1");
$(".add").click(function() {
addRows();
});
$(".delete").click(function() {
deleteRows();
});
function addRows() {
$tab = $(".table1");
$("<tr class='raja'><td>rajasekhar</td><td>hostanalytics</td></tr>").appendTo($tab);
$(".raja").click(function() {
$tab.removeClass("selected");
$(this).addClass("selected");
});
}
function deleteRows() {
$(".selected").remove();
}
});
</script>
</head>
<body>
<div class="div1">
</div>
<input type="button" class="add" value="InsertRow" />
<input type="button" class="delete" value="DeleteRow" />
</body>
Upvotes: 0
Views: 165
Reputation: 15835
Raja sekhar ,
As thumb or rule always use live instead of bind when you are dynamically adding and deleting html
$('.test').live('click', function() {
// Live handler called.
});
read more here
Upvotes: 2