Reputation: 2302
Given the code like this
<table>
<tr>
<td>1</td>
<td>e</td>
<td>a</td>
</tr>
<tr>
<td>2</td>
<td>e</td>
<td>c</td>
</tr>
...
</table>
The first cell of every row is the id (it's unique) If the input is value of the id, how can I get the value of the third cell in this row
Example: input 1 -> output a
input 2 -> output c
How can I do it with Jquery?
Upvotes: 1
Views: 72
Reputation:
this exactly what you want.
you can use Demo Link
And function look like
$(document).ready(function() {
$('table tr').each(function() {
var str = "input "+ $(this).find('td:first').text() + " -> output " + $(this).find('td:last').text();
$("#result").append("</br>"+str);
});
});
Upvotes: 1
Reputation: 17257
You can do something as below
var valueSearch = "4";
$('tr').each(function(index){
if($(this).find('td:first').text()==valueSearch){
alert($(this).find('td:last').text());
}
});
Here is a working example at live fiddle
$('tr').eq("1").find('td:last').text();
Is the correct way of doing it.
Here is a live example on Fiddle
Upvotes: 3
Reputation: 9297
Using JavaScript, you can use this
var id = document.getElementsByTagName('tr')[0].getElementsByTagName('td')[0].innerHTML;
var value = document.getElementsByTagName('tr')[id].getElementsByTagName('td')[2].innerHTML;
Upvotes: 1
Reputation: 28753
Try like
$('table tr').each(function(){
alert("input "+ $(this + 'td').eq(0).text() + " -> " + $(this + 'td').eq(2).text());
});
or try like
$('table tr').each(function(){
alert("input "+ $(this + 'td:first').text() + " -> " + $(this + 'td:last').text());
});
Upvotes: 1