Mega Code Archive

 
Categories / JavaScript Tutorial / JQuery
 

Clone table row

< html>   <head>     <script type='text/javascript' src='js/jquery-1.3.2.js'></script>     <script type='text/javascript'> $(document).ready(   function() {     $('input#tmpAddRow').click(       function($e) {         $e.preventDefault();         $('tr#tmp').clone(true).removeAttr('id').appendTo('tbody');       }     );     $('tr input[type=text]').focus(       function() {         $(this).addClass('myFocused');          }     ).blur(       function() {         $(this).removeClass('myFocused');       }     );   } );     </script>   </head>   <body>      <form >        <table>          <thead>            <tr>              <th>Title</th>              <th>Selected</th>                    </tr>          </thead>          <tbody>            <tr id='tmp'>              <td><input type='text' name='tmpTitle[]' value='0' /></td>              <td><input type='checkbox' name='tmpTitleChecked[]' value='1' /></td>            </tr>          </tbody>        </table>        <input type='submit' id='tmpAddRow' value='Add a Row' />      </form>   </body> </html>