0

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?

0

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.