I am trying to get the value of a form element using the closest. Here is a sample code.
<table> <tr> <td>Hour <input type="input" value="12" name="data[hour]" class="hour" /></td> <td>Minute <input type="input" value="12" name="data[minute]" class="minute" /></td> <td><a href="#" class="add-data">Add Row</a></td> </tr> </table>
See, I cannot serialize the form because it is part of a large form, so I need to grab every input closest to the add line link, since yo will be able to add multiple lines.
I tried
var hour = $(this).closest('.hour').val(); var hour = $(this).closest('input', '.hour').val(); var hour = $(this).closest('input[name="data[hour]]").val();
Any ideas how I can get the values โโof the form?
Thanks in advance
source share