$(".country_selector").change( function(){ if ($(".region_selector").length > 0){ $.getJSON('/countries/'+$(this).val(), function(data) { $(".region_selector").html($("<option></option>")); $.each(data.country.regions, function(index, region){ $(".region_selector"). append($("<option></option>"). attr("value",region.id). text(region.name)); }); }); } });