maybe i need to be more specific in where i post my questions coz i posted one in web development. so ill reiterate im trying out this cloning and toggling thing to see if they could work together. ive got a table like so:
<table class="StateTable" rules="all" cellpadding="0" cellspacing="0">
<thead>
<tr class="statetablerow">
<th style="width:33%">Table</th>
</tr>
</thead>
<tbody>
<tr id="2">
</tr>
</tbody>
</table>
and another which if u notice has style display:none:
<table class="CityTable" rules="all" cellpadding="0" cellspacing="0" style="display:none" id="scroll">
<thead>
<tr>
<th style="width:33%">Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name #1</td>
</tr>
<tr>
<td>Name #2</td>
</tr>
<tr>
<td>Name #3</td>
</tr>
</tbody>
</table>
what im trying to do is clone table ".CityTable" into table ".StateTable" after button click and thats working just fine. the issue im facing is that the th of .CityTable is suppose to toggle when it gets cloned into ".StateTable". ".CityTable" toggles just fine if it is not cloned and displayed as it is, it's only when it's cloned the toggle doesnt work.
<button class="dip">Clone 3</button>
toggle:
<script type="text/javascript">
$(document).ready(function(){
$('.CityTable thead').click(
function() {
$(this) .parents('.CityTable').children('tbody').toggle();
}
)
});
</script>
i tried swapping/changing the name for parents
and children
and the element that click, but i dont think its right or if i did it right coz it didn't work anyway.
clone:
<script>
$(document).ready(function($) {
$(".dip").click(function() {
$('#scroll')
.clone()
.removeAttr('id')
.show()
.appendTo( $('#2').parent() );
});
});
</script>
is this not the right way? is there a different way of approaching this? thanks in advance!