I'm trying to reference a th relating to a td within the same tr, unfortunately the headers and classes do not correspond so I cannot just create another .each loop.
I've had a play with adapting this answer which references a vertical heading but with no success.
Thanks all for your help.
Example Row
<tr>
<th id="row_51_18" class="level3 levelodd item b1b column-itemname" colspan="1"><a title="Link to Quiz activity" href="http://virtualmedics.org/mod/quiz/grade.php?id=93&itemnumber=0&userid=18"><img class="icon itemicon" alt="Quiz" title="Quiz" src="http://virtualmedics.org/theme/image.php?theme=vmelegance&amp;component=quiz&amp;image=icon">Acute Appendicitis</a></th>
<td headers="cat_23_18 row_51_18 percentage" class="level3 levelodd item b1b itemcenter column-percentage">79 %</td>
<td headers="cat_23_18 row_51_18 average" class="level3 levelodd item b1b itemcenter column-average">65 %</td>
<td headers="cat_23_18 row_51_18 feedback" class="level3 levelodd item b1b feedbacktext column-feedback"> </td>
</tr>
Javascript
$("[id^=cat_]").each(function(i,obj){
var gatherLabels = [];
var gatherValues = [];
$('td[headers*="' + obj.id + '"]').each(function(i, obj) {
if ($(obj).hasClass("column-percentage")) {
gatherLabels.push(obj.closest('tr').child('th').innerText); // 'undefined'
gatherValues.push(obj.innerText.replace('%', '')); // Working fine
}
});
Questions
- How can I select the text within the corresponding th for each td
- Is declaring obj twice (within both .each) an awful thing to do.... seems to not matter