1. It is not clear why with 2 and 3 examples, I do not get the list as in the first? Logically, it should give me a list .. Instead, I get the first value from the entire list.

  2. How to display a list of Id attribute values ​​from each form?

1.var setOfForms = $("#ATemplate > form"); console.log(setOfForms); 2.var setOfForms2 = $("#ATemplate > form").attr("id"); console.log(setOfForms2); // Почему я не получаю спсиок значений атрибута ID ? 3.var forms = $("form").attr("id"); console.log(forms); // Почему я не получаю спсиок значений атрибута ID ? 

enter image description here

    1 answer 1

    How to display a list of Id attribute values ​​from each form?

    Option 1

     var id = $("#ATemplate > form").map(function() { return $(this).attr("id"); }); console.log(id); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="ATemplate"> <form id="test1"> </form> <form id="test2"> </form> <form id="test3"> </form> </div> 

    Option 2

     var id = []; $("#ATemplate > form").map(function() { id.push($(this).attr("id")); }); console.log(id); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="ATemplate"> <form id="test1"> </form> <form id="test2"> </form> <form id="test3"> </form> </div> 

    PS: instead of map () you can use each () .