title: How to push the ids of selected option of dropdowns into an array using jquery?
body: <p>Hi I am new to jquery actually I had an dropdown in my html where I will get the options from database using ajax here I am retrieving the id and option from database but showing only the options in the dropdown</p>
  <p>The code for dropdown which I done so far in html is</p>
  <pre><code>&lt;div id=&quot;container&quot; class=&quot;&quot;&gt;&lt;/div&gt;
  &lt;button id=&quot;seedoc&quot; style=&quot;float: right; margin-right: 10px;&quot; onclick=&quot;addOne();&quot;&gt;&lt;/button&gt;
  function addOne() {
  getEmails();
  $('#container').append(
  &lt;div class='form-group' style='display:flex'&gt;
  &lt;select class='drop form-control'  name='option' id='option'&gt;
  &lt;option value='' disabled selected&gt;Select your option&lt;/option&gt;
  &lt;/select&gt;
                  &lt;button class=&quot;btn btn-primary shrBtn&quot; style=&quot;float:left;&quot; onclick=&quot;send()&quot;&gt;Send&lt;/button&gt;
  
  &lt;/div&gt;
  </code></pre>
  <p>the json response I get from db.php is</p>
  <pre><code>users:
  [ &quot;&lt;p style='margin:0px;display:none;'data-id='755'&gt;amilham&lt;/p&gt;&quot;,
  &quot;&lt;p style='margin:0px;display:none;'data-id='706'&gt;a_sarabi&lt;/p&gt;&quot;]
  </code></pre>
  <p>and in dropdown I am getting amilham,a_sarabi so here in the dropdown if I select amilham I need to get the data-id i.e 755 into an array and also in the another dropdown if I select a_sarabi I need to get 706 into array using jquery</p>
  <p>can anyone help me please</p>
  <p>so far I tried like this but not getting</p>
  <pre><code>function send()
  {
      var uids = [];
      \$('.drop').change(function(){
     \$(this).find('option:selected').each(function(){
         uids.push(\$(this).attr('data-id') );
      });
     });
  </code></pre>
  <p>I need all the ids of selected options in all the dropdowns I add using jquery
  Populating options from db into dropdown</p>
  <pre><code>function getEmails(){
          
      
      \$.ajax({
          url :'propage.php',
          type : 'POST',
          dataType : 'json',
          data : '&amp;userId='+\$('#hdn_userid').val()+'&amp;action=getEmails',
          success : function(res){
              res.users.forEach(function(option) {
              \$('.drop').append('&lt;option&gt;' + option + '&lt;/option&gt;');
          });
        },
      });
    }
  </code></pre>