So I have a dynamic list of textboxes that have all the same class, like so:
<input type="text" id="value1" class="list-value" />
<input type="text" id="value2" class="list-value" />
<input type="text" id="value3" class="list-value" />
<input type="text" id="value4" class="list-value" />
So when a link is clicked, I need the values from all those textboxes to be loaded into an array:
$('a#link').click(function() {
//add to array here
});
How can I do that?
You can do this:
The “.map()” method will iterate through the list of elements like “.each()”, but it takes the return value and accumulates an array. The final “.get()” is necessary to get a “raw” array instead of a jQuery object (a wrapper around the array), but that’s not always necessary; it depends on what you want to do with the result.