Q:

Grab value from the user input field

I have a question regarding the user input field issue. 
I am trying to grab the data from the input field after user enter something.
My html:
<div>texts here <input type='text'></input></div>

<div>
  <table>
     <tr>
        <td>cell here</td>
        <td>cell here</td>
     </tr>
     <tr>
        <td>another cell here</td>
        <td><input type='text'></input></td>
     </tr>

  </table>
</div>

My js
var test = $('input).val();
var test2 = $('input).html();

console.log(test)
console.log(test2)

Both of them will show the first texts that are entered in the first input field but not the second within the table.
Can someone please help me about it? Thanks a lot!

A:

$('input') refers to a jQuery object with multiple elements, calling a function like val() or html() will return the value of the first matched element only.
To get all values you'd need to loop through each element in the object:
$('input').each(function(){
    console.log($(this).val());
});

