Id multple selectbox

Get id from multiple select box

by wenyi

HTML

<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<form>
  <label>Country:</label>
  <select class="country" multiple="multiple">
    <option id="1">United States</option>
    <option id="2">India</option>
    <option id="3">United Kingdom</option>
    <option id="4">Brazil</option>
    <option id="5">Germany</option>
  </select>
  <button type="button">Get Values</button>
</form>

CSS

/* Latest compiled and minified CSS included as External Resource*/


/* Optional theme */

@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
  margin: 10px;
}

JavaScript

$(document).ready(function() {

  $("button").click(function() {
    var countries = [];
    $.each($(".country option:selected"), function() {
      countries.push($(this).attr("id"));
    });
    console.log($(".country").val().join(','));
  });
  
});