0

I have html table in partial view.

I want to add more table data to table row. Need to mention I have created only one table row having all table data inside horizontally.

I need to add more table data after button click event. But my last table data is Total, so i need to add table data before Total column. It is html mark up so I don't have way to show that.

My table is like that.

<table>
    <tr><td>1</td><td>2</td><td>3</td><td>4</td><td>Total</td></tr>
</table>

I want to add new column before Total column, like that.

<table>
    <tr><td>1</td><td>2</td><td>3</td><td>4</td><td>Add New Column</td><td>Total</td></tr>
</table>
yeyene
  • 7,297
  • 1
  • 21
  • 29
unique
  • 5,442
  • 6
  • 23
  • 26

2 Answers2

3

Not sure exactly what you mean, but check this DEMO http://jsfiddle.net/yeyene/UDV64/

Is that what you want?

$(document).ready(function(){
    $('#add').on('click', function(){
        var $getCol = $('#myTable tr > td');
        $getCol.eq($getCol.length-1).before('<td>New</td>');
    });
});
yeyene
  • 7,297
  • 1
  • 21
  • 29
-1

EDIT -> Already posted: Add table row in jQuery

This is what you will need to use: http://api.jquery.com/last-selector/

You can use this with .append or .insertAfter

jQuery has great documentation so make sure you read through and look at the examples.

Community
  • 1
  • 1
m33bo
  • 1,334
  • 1
  • 17
  • 34