Get Hyperlink Text of a Datatable Cell
by Shree Khanal
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.21/js/jquery.dataTables.min.js"></script>
<table id="sampleTable">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#">R0C1</a></td>
<td>R0C2</td>
<td>R0C3</td>
</tr>
<tr>
<td><a href="#">R1C1</a></td>
<td>R1C2</td>
<td>R1C3</td>
</tr>
<tr>
<td><a href="#">R2C1</a></td>
<td>R2C2</td>
<td>R2C3</td>
</tr>
</tbody>
</table>
<button>
Click
</button>
JavaScript
$(function() {
var table = $('#sampleTable').dataTable();
$('button').click(function() {
var oTable = $('#sampleTable').dataTable();
var result=[];
var rows = $("#sampleTable").dataTable().fnGetNodes();
for(var i=0;i<rows.length;i++) {
//Get HTML of 3rd column (for example)
console.log($(rows[i]).find("td:eq(0)").text());
}
});
});