Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Less Coupled
var CountrySelectClass = function() {
var countriesIveBeenTo = {
'BE': 'Belgium',
'CR': 'Costa Rica',
'IT': 'Italy',
'US': 'United States of America',
'UK': 'United Kingdom'
};
this.init = function(selector) {
this.$el = $(selector);
$.each(countriesIveBeenTo, function(val, text) {
this.$el.append(
$('<option value="' + val + '">' + text + '</option>')
);
}.bind(this));
this.$el.change(function() {
console.log('Selected country: ' + this.$el.find(':selected').text());
}.bind(this));
};
};
$(function() {
$(document.body).append( $('<select id="countries"></select>') );
var csInstance = new CountrySelectClass();
csInstance.init("#countries");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment