I don't understand where you can use parents and find. I have code that use both but in some cases they don't work
What I am trying to do is start from some location inside of a "td" and go up to the parent "tr" and then do a find on class of a label in the same row. It works in other cases fine.
If I have the following:
And I use the following script to push a button in the grid and go find an input. I save the jquery that finds that to use later after I come back from a modal window where I am doing a save.
I push a button that is outside of the grid and the jquery wants to update the text in the label from the same row I pushed the button on.
But if I try to use "...parents('tr')", I get an error, even though I am pointing at the 'td' element.
If I try to use parentElement (twice) to get to the "tr", I can't use the find to get to the label element.
Why not?
Here is the script:
This works fine:
$('#input2').parents('tr').find('.nc-count')[0].innerText
Which is really the same thing.
Thanks,
Tom
What I am trying to do is start from some location inside of a "td" and go up to the parent "tr" and then do a find on class of a label in the same row. It works in other cases fine.
If I have the following:
Code:
<table style="border:1px solid black">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input id="input1" type="text" />
<input id="input2" type="text" />
<input id="input3" type="text" />
</td>
<td>
<button id="button1" class="row-buttons"/>
<span>
<label class="nc-count">5</label>
</span>
</td>
</tr>
<tr>
<td>
<input id="input4" type="text" />
<input id="input5" type="text" />
<input id="input6" type="text" />
</td>
<td>
<button id="button2" class="row-buttons" />
<span>
<label class="nc-count">5</label>
</span>
</td>
</tr>
</tbody>
</table>
<button id="button3">Save</button>
And I use the following script to push a button in the grid and go find an input. I save the jquery that finds that to use later after I come back from a modal window where I am doing a save.
I push a button that is outside of the grid and the jquery wants to update the text in the label from the same row I pushed the button on.
But if I try to use "...parents('tr')", I get an error, even though I am pointing at the 'td' element.
If I try to use parentElement (twice) to get to the "tr", I can't use the find to get to the label element.
Why not?
Here is the script:
Code:
<script type="text/javascript">
var td;
var saveLocation;
$(".row-buttons").click(function () {
debugger;
// the following points at the "input2" element.
// I then save this location so I can come back to this row from a modal dialog
saveLocation = $(this)[0].parentElement.parentElement.children[0].children[1];
});
$("#button3").click(function () {
debugger;
// saveLocation.parentElement.parentElement points at the "tr"
// I want to go up to the "tr" element then find the label that has "nc-count" in this row
// Following statements give me an "object doesn't support property..." error (parents and find);
saveLocation.parents('tr');
// 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'parents'
saveLocation.parentElement.parentElement.find('.nc-count');
//0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'parents'
});
</script>
This works fine:
$('#input2').parents('tr').find('.nc-count')[0].innerText
Which is really the same thing.
Thanks,
Tom