<!DOCTYPE html>

<html>

<head>

<title>jQuery Table</title>


<style type="text/css">

body {

font-family: sans-serif;

}


table {

border-collapse: collapse;

margin-bottom: 5px;

}


td {

padding: 4px;

border: #4488aa 1px solid;

}


input {

text-align: right;

padding: 2px;

width: 20px;

}

</style>


<script type="text/javascript"

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">

</script>


<script type="text/javascript">

$(function() {

$('td').click(function() {

var tr = $(this).parent();

for (var i = 0; i < tr.children().length; i++) {

if (tr.children().get(i) == this) {

var column = i;

break;

}

}


var tbody = tr.parent();

for (var j = 0; j < tbody.children().length; j++) {

if (tbody.children().get(j) == tr.get(0)) {

var row = j;

break;

}

}

$('span').text(row + ', ' + column);

});

});

</script>

</head>


<body>

<h1>Table Cell Value</h1>

<table>

<tr><td>Cell 1-1</td><td>Cell 1-2</td><td>Cell 1-3</td></tr>

<tr><td>Cell 2-1</td><td>Cell 2-2</td><td>Cell 2-3</td></tr>

<tr><td>Cell 3-1</td><td>Cell 3-2</td><td>Cell 3-3</td></tr>

</table>


You clicked cell: <span>None</span>

</body>

</html>

 

 

Simple jQuery code snippet to remove an entire table column based on the column number. It also removes the table row heading associated with the removed column.



//remove the 1st column


$('#table').find('td,th').first().remove();

//remove the 1st column


$('table tr').find('td:eq(1),th:eq(1)').remove();

//remove the 2nd column


$('table tr').find('td:eq(1),th:eq(1)').remove();

//remove the nth column


$('table tr').find('td:eq(n),th:eq(n)').remove();