Getting undefined with the below code..
Hi,
This is my code, I am trying to get the attribute of previous td child from current td input, kindly see the below and suggest me the solution.
HTML
- <html>
- <head><title>I am a beginner</title></head>
- <body>
- <table><thead/><tbody>
- <td><input name="1sttextbox" type="text" value="10/22/2015" id="1"/></td>
- <td><input name="2ndtextbox" type="text" value="10/23/2015" id="2"/></td>
- <td><input name="3rdtextbox" type="text" value="10/21/2015" id="3"/></td>
- </tr></tbody>
- </table>
- </body>
- </html>
Jquery
- $(function() {
- var input=$("input[type='text']");
- input.blur(function() {
- var val1=$(this).val();
- var val2 = $(this).closest('td').prev('td input').attr('value');
- alert(val1);
- alert(val2);
- return false;
- });
I am getting the val1 in alert box but in undefined for val2. Please check and suggest solution.