-1

I have a html table with 4 tablecells: 1: Checkbox 2. label 3. textbox 4. label

Once I click on the checkbox, a jquery function fires, but im trying to get the values next to the checkbox. I have tried below, but nothing works. I know I am close. Any help would be very much appreciated.

$(this).next()
$(this).nextSibling
$(this).nextSibling.childNodes[0]


 <table id="MainContent_cockpitTable" style="width:80%;">
  <tr>
<td>
      <input id="MainContent_check_FLIGHT DECK1" type="checkbox" checked="checked"/>    
    </td>
     <td>Pilot</td>
     <td><input "type="text" value="86.2" maxlength="10" id="MainContent_input_FLIGHT DECK_weight1" />
     </td>
     <td><span id="MainContent_input_FLIGHT DECK_arm1" style="display:inline-block;width:50px;">255.0</span></td>
</tr>
 </table>
4

3 に答える 3

2
$(this).parents('tr').find('label').text()

http://jsfiddle.net/7jnTF/2/

于 2012-11-14T21:35:37.433 に答える
1
$(this).next('td').html(); 

or

$(this).next('td').text(); 

This should work - ( i think ) that you have something like

<table>
  <tr>
    <td> <input type=checkbox .... /> </td>
    <td> YOU WANT THIS LABEL </td>
    <td> <input type=textbox ..... /> </td>
    <td> ANOTHER LABEL </td>
  </tr>
</table>
于 2012-11-14T21:40:14.807 に答える
0

Working demo http://jsfiddle.net/suSkb/

Your case specific demo http://jsfiddle.net/7nyn8/

Please note: classes can have spaces but not id and id should be unique.

Hope it fits your cause :)

Code

$('.hulk').click(function(e) {
    alert($(this).parents('tr').html());
     alert('Lable HTML = > ' + $(this).parents('tr').find('lable').text())   
});
​

further

$('.hulk').click(function() {
    alert($(this).parents('tr').html());
    alert('Pilot here:=> ' + $(this).parent().next().html());
    alert('Lable HTML = > ' + $(this).parents('tr').find('span').text())
});​
于 2012-11-14T21:42:51.283 に答える