How to get all values ​​of text inputs using jQuery?

I have a table with a column of pre-filled text inputs:

    <table><tr><td>...</td><td><input class="unique_class" value="value1"/></td></tr>...


I gave each input field the same css class that only this element has (unique_class). I was hoping that I could use jQuery.val () to grab an array of all input values ​​with a css class in the table like this (I did something similar with checkbox values):

    var values = $('.unique_class').val();


However, I only get the value of the last entry in the table. Is there a simple "quick" way to do this without iterating over the for-loop? Can this table be very large (more than 100 rows)?


source to share

2 answers

To get an array of values, you must use the method $.map


var values = $('.unique_class').map(function() {
    return $(this).val();


Also notice how you are using the method .get

to convert a jQuery type array to an actual array.



Maybe you can try this:

 var values = $('td.unique_class').val();




All Articles