in IE8,Add a new row before the last row to HTML table using Jquery -
i need add new row before summary row table. able add new row before summary row problem cells have text field elements , non-editable. how create row taken consideration. please find below code adding new row before last row.
<table id="samptable"> <thead> <tr> <td>column 1</td> <td>column 2</td> <td>column 3</td> <td>column 4</td> <td>column 5</td> </tr> </thead> <tbody> <tr> <td><input type="text"/></td> <td><input type="text"/></td> <td><input type="text"/></td> <td></td> <td></td> </tr> <tr id="summaryrow"> <td><input type="text"/></td> <td><input type="text"/></td> <td><input type="text"/></td> <td></td> <td></td> </tr> </tbody> </table> <br> <button id="addbtn" onclick="addtablerow($('#samptable'));">add row</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> function addtablerow(jqtable){ jqtable.each(function(){ var $table = $(this); // number of td's in last table row var n = $('tr:last td', this).length; var tds = '<tr>'; for(var = 0; < n; i++){ tds += '<td><input type="text" class="tb-input"/></td>'; } tds += '</tr>'; if($('tbody', this).length > 0){ // $('tbody', this).append(tds); $('tr:last',this).before(tds); }else { $(this).append(tds); } }); } </script> the above code adds text field element columns. don't need it, me columns contain text fields , non-editable.
the reason should ie8- has bad syncronization dom added string. resolve adding jquery object instead of string.
so in case
var $tds = $('<tr>'); //this create jquery object /* other code here */ $(this).append(tds); //this add objet dom i made fiddle in order make clear.
Comments
Post a Comment