Jesse McMillan Jesse McMillan - 1 month ago 6
Javascript Question

jquery how do I find value of input within table?

I'm an absolute novice at jquery.

Currently I have a table row:

<tr id="someID">
<td class="pin"><input type="text">/td>
<td><button class="addpin" type="button">ADD</button></td>
</tr>


I'm having a hard time getting the value of the text input. Here's what I have:

$(document).on('click', ".addpin", function() {
var mypin = $(this).parent().siblings(".pin").html();
alert(mypin);
});


which alerts:

<input type="text">


but when I try:

$(document).on('click', ".addpin", function() {
var mypin = $(this).parent().siblings(".pin").val();
alert(mypin);
});


it's blank no matter what's in the input. What am I doing wrong?

Answer
var mypin = $(this).parent().siblings(".pin").children(0).val();

This will need to be adjusted if you put anything else into this cell.