Finding parent class and id
Well, after countless tries, I can't get this to work?
<script type="text/javascript">
$("td input").focusout(function() {
var column = $(this).parent('td').attr('class');
var row = $(this).parent('tr').attr('id');
$('#dat').HTML(row+" "+column);
});
</script>
And the html looks like this
<tr class="numbers" id="1">
<td class="a" align="right">1</td>
<td class="b"><input class="input" type="text" value=""/></td>
<td class="c"><input class="input" type="text" value=""/></td>
<td class="d"><input class="input" type="text" value=""/></td>
<td class="e"><input class="input" type="text" value=""/></td>
<td class="f">0</td>
<td class="g"><input class="input" type="text" value=""/></td>
</tr>
Can anyone point me in the right direction what might be wrong? thanks in advance
considers
+2
a source to share
4 answers
You want to use the function .parents()
, not .parent()
.
The reason, from the documentation, is my highlight.
Given a jQuery object that represents a set of DOM elements, the .parent () method allows us to parent those elements in the DOM tree and construct a new jQuery object from the corresponding elements. The.parents () and .parent () are similar, except that the latter is moved one level up the DOM tree.
0
a source to share