I have a table with a column of pre-populated text inputs:
<table><tr><td>...</td><td><input class="unique_class" value="value1"/></td></tr>...
I gave each input box the same css class that only that element has (unique_class). I was hoping that I could use jQuery.val() to grab an array of all the input values with the css class in the table like this (I have done something similar with checkbox values):
var values = $('.unique_class').val();
However, I only am getting the value of the last input in the table. Is there a simple 'fast' way to this without a for-loop iteration? This table can get be very large (100+ rows)?
To get an array of values you should use $.map method:
var values = $('.unique_class').map(function() {
return $(this).val();
}).get();
Also note, how you use .get method to convert jQuery array-like collection to actual array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With