$.fn.dataSelected = function() { $(this).each(function() { var this_value = this.getAttribute('data-selected'); $(this).find('option[value=' + this_value + ']').attr('selected', true); }); };