I have this code:
<c:forEach items="${ sample }" var="test">
<tr>
<td><strong>${ test.test }.</strong></td> // I want to get the text
<td>
<fieldset class="span11">
<div class="control-group">
<label class="control-label"><strong>${ test.blah }</strong></label>
<div class="controls" id="question${ test.blah }">
<c:forEach var="beng" items="${ anotherSample }">
<form:radiobutton path="boom" class="question-choices" data-label="${ choices }" value="${ beng-boom }"/><br>
</c:forEach>
</div>
</div>
</fieldset>
</td>
</tr>
</c:forEach>
I want to get the text from the first <td> from the radio button:
What I tried so far is:
$('.question-choices').on('change', function() {
console.log( $(this).parent('tr').closest('td').text() );
});
But this returns empty string
parents('tr')seems to do what OP wants. Could be a typo.parents()is a bad choice.