Not able to get siblings value from table row
Posted
by Sullan
on Stack Overflow
See other posts from Stack Overflow
or by Sullan
Published on 2010-05-24T10:47:18Z
Indexed on
2010/05/24
10:51 UTC
Read the original article
Hit count: 244
jQuery
|jquery-selectors
Hi All,
I am trying to get values from adjacent columns, when a radio button is clicked for that row. I'm able to do so, but the problem I'm facing, when there are more elements in the radio button column, then i am getting null values(i.e 2nd row is not working). Please help...Code is all follows
<table id="dist_list" class="data">
<tbody>
<tr>
<td>
<input type="radio" value="636406" name="distRG" id="radio_7" /></td>
<td class="selected">Company 1</td>
<td class="siteId">1234</td>
<td class="siteName">First Company Name</td>
</tr>
<!-- Not able to get values from this row, since there are more elements in it -->
<tr>
<td>
<span class="jqTransformRadioWrapper"><a rel="distRG" class="jqTransformRadio" href="#"></a>
<input type="radio" value="636406" name="distRG" id="radio_2" />
</span></td>
<td class="selected">Company 2</td>
<td class="siteId">2345</td>
<td class="siteName">Second Company Name</td>
</tr>
<tr>
<td><input type="radio" value="636406" name="distRG" id="radio_3" /></td>
<td class="selected">Company 3</td>
<td class="siteId">3456</td>
<td class="siteName">Third Company Name</td>
</tr>
<tr>
<td><input type="radio" value="213584" name="distRG" id="radio_4" /></td>
<td class="selected">Company 4</td>
<td class="siteId">4567</td>
<td class="siteName">Fourth Company Name</td>
</tr></tbody></table>
jQuery script
$("input[name=distRG]").click(function() {
var owner = $(this).parent().siblings('td.selected').text();
var siteId = $(this).parent().siblings('td.siteId').text();
var siteName = $(this).parent().siblings('td.siteName').text();
alert(owner);
alert(siteId);
alert(siteName);
});
© Stack Overflow or respective owner