-1

I have a given row object $row and there are already columns in it, I would like to insert a new column with html text at first position.

like

var cell = $row.insertCell(0);
cell.innerHTML = "<input type='button' value='Add'/>";
rrk
  • 15,677
  • 4
  • 29
  • 45
  • did you try using prepend ? `$row.prepend(cell) ` . See -> https://api.jquery.com/prepend/ – Mihai T Aug 26 '19 at 11:33
  • Possible duplicate of [Jquery insert new row into table at a certain index](https://stackoverflow.com/questions/3577860/jquery-insert-new-row-into-table-at-a-certain-index) – Kalaiselvan Aug 26 '19 at 11:35
  • And what errors were reported? What is `$row`, a jQuery object? Where’s your relevant “*[mcve]*” code sample? Please, take the [tour], and read the “*[ask]*” guidelines. – David Thomas Aug 26 '19 at 12:20

1 Answers1

0

You can try this script to solve your issue.

<!DOCTYPE html>
<html>
<head>
<title>Try jQuery Online</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
   var row = $("#tbl1-tr0");
   var cell = document.createElement("td");       
   row.find('td').eq(0).before(cell);
   cell.innerHTML = "<input type='button' value='Add'/>";       
});    
</script>
</head>
<body>    
<table id="tbl1">
    <tr id="tbl1-tr0">
        <td>Name</td>
        <td>Age</td>
    </tr>
</table>
</body>
</html>
Sanjib Pal
  • 148
  • 6