Reputation: 1742
I want to save the ID of each input element of the form which form element I clicked into an array.
var element = $(element);
var $formID = element.closest('form').prop("id") || "";
var formElementsIDs = []; // What to do?
There, I got the form ID. How do I get each form element from here?
Upvotes: 0
Views: 39
Reputation: 82251
You can use .map()
and .get()
with appropriate selector to get all the ids in array :
var ids=$(element).closest('form').find('input').map(function() {
return this.id;
}).get();
Upvotes: 0
Reputation: 67217
Try to use .map()
along with .get()
to collect all the input element's id in an array,
var formElementsIDs = element.closest('form').find('input').map(function(){
return this.id || '';
}).get();
Upvotes: 2