Using JQuery, I need to know if the User clicked on the link or third column, and need to get the value of the variable in the first column. How do I do this?
My html:
<div id="test">
<table id="tablex" cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>Cod</th>
<th>Name completo</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John Foster 1</td>
<td><img entity_id="1" class="image-selector" src='imagens/grid_cancel.png' title='' /></td>
</tr>
</tbody>
</table>
My jQuery:
$("#tablex tbody").on("click", "td", function(event){
alert($(this).text());
});
$("#tablex tbody").on("click", "td", function(event){
alert($(this).index());
alert($(this).siblings("td:first").text());
});
$(this).index()
will give you the zero-based index of the clicked column.
$(this).siblings("td:first").text()
will give you the text in the first column.
Here, have a fiddle: http://jsfiddle.net/adrianonantua/EAEsG/
This will give you the column number of the clicked column, and the value of the 1st column...
$("#tablex tbody").on("click", "td", function(event){
var index = $(this).index();
var col1value = $(this).parent().find("td").first().text();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With