gaurav oberoi
gaurav oberoi

Reputation: 463

button not doing an event more than once

I am using a script which is adding a new row () after the tr in which my button (to be clicked) is. i didnot want the SAME button to produce more than one tr . here is the script:

<script>

 $(function() {
        var done;
        $('table.listtable td input.selectseat').click(function() {

            if( done ) return;
            done = true;
           $(this).parent().parent().after('<tr class="seating"><td colspan="6"></td></tr>');
        });
    }); 

</script>

but the proiblem is that i have sequesnce of these buttons, and what this script is doing is, that its not letting me produce a row FROM ANOTHER BUTTON after i have produced a row from a button. to clearly put it, i have a sequence of rows , each having the same button called "select seats". i wanted that EACH BUTTON should not produce more than one button, but we can have every different button clicked and produce a row at the same time, which is not happeining.

the statement-:

if( done ) return;
            done = true;

was added to prevent the button clicked already, not to produce any more row, but its not producing a new row after one click at all for all the buttons. please help.

Upvotes: 0

Views: 89

Answers (1)

recursive
recursive

Reputation: 86064

That is what one is for.

$('table.listtable td input.selectseat').one('click', function() { ... } );

Upvotes: 3

Related Questions