Q:

jquery, using $.each() to add options to a select

I'm attempting to populate two <select> elements with monthly values. Instead of duplicating the logic for doing so, I'm attempting to use jQuery's $.each() to make this happen. Here's some code:
for ( var i = 0; i < 12; i++ )
{
  var cm = moment().month(i);
  $( '#m1, #m2' ).each( function( i, el ) {
    $( el ).append( $( "<option />" ) ).val( cm.format( "MM" ) ).text( cm.format( "MMM" ) ) ;
  });
}

I think in theory what I'm trying to do is correct, just syntactically not compliant with jQuery. The problem I'm running into is the option elements are not being appended. If I replace the $.each() code and just the same exact thing for $( '#m1' ) and $( '#m2' ) individually, it'll work. So the problem is most likely on how I'm using $.each()
This is using jQuery 3.1.0.

A:

You have the .val() and .text() assigned to the wrong element.  Your .append() line should read as follows:
$(el).append( $("<option />").val(cm.format( "MM" )).text(cm.format( "MMM" )) ) ;

Similarly, the easiest way would be to avoid the .each() loop entirely and just call the .append() method:
$("#m1, #m2").append( $("<option />").val(cm.format( "MM" )).text(cm.format( "MMM" )) );

