jquery - I'm trying to select the checkbox type of input and then appending table column -
i have multiple inputs type checkbox - , if 1 of them checked, want append column (just 1 time) - i.e. if of other checkbox types marked after first 1 is, not want add column again, keep doing. did adding once per each checkbox type input. however, want add column once across whole document (i.e. across checkboxes on page).
here's relevant parts of code
<table id="edhist_table" > <tr id="table_headings"> <th>graduated?</th> </tr> <tr> <td><input type="checkbox" name="college_grad" value="yes">yes</input></td> </tr> <tr id='grad_part'> <td><input type="checkbox" name="grad_grad1" value="yes">yes</input></td> </table> <script> //if of checkboxes checked - shoudl append column $( "[type=checkbox]").one("click",function() { $( "#table_headings" ).append("<th id='degree_heading'>degree/certificate name</th>");
any ideas appreciated.
the .one
execute @ 1 per element means fire each element 1 time (this causing duplicates. need check if element has been added , if not add it. can change this:
$( "[type=checkbox]").one("click",function() { if ( $( "#table_headings #degree_heading" ).length==0) $( "#table_headings" ).append("<th id='degree_heading'>degree/certificate name</th>"); });
Comments
Post a Comment