Setup:
I have written a jQuery function to update table cells of table_2, when a row in table_1 is clicked. Here is what I have written:
<script type="text/javascript">
$("tr").live('click',function() {
var host = $(this);
alert('A row in table 1 is clicked!');
var count = host.find("td").eq(2).text();
$("#myTable_2 tr:eq(0) td:eq(1)").text(count);
$("#myTable_2 tr:eq(1) td:eq(1)").text(5);
});
</script>
The Problem:
When I step-through this function using FireBug, I can see the cell data in myTable_2 is being changed. BUT, for every click, the function is executed twice. I can see the alert box appearing twice for each click.
Can somebody tell me why does this happen? And how to avoid this?
just simply avoid the propagation of the click
$("tr").live('click',function() {
...
$( event.toElement ).one('click', function(e){ e.stopImmediatePropagation(); } );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With