Skip to content

Instantly share code, notes, and snippets.

@mehdichaouch
Created June 19, 2017 22:04
Show Gist options
  • Save mehdichaouch/1c4a61486553bb257a2a4be4c3ed1ec8 to your computer and use it in GitHub Desktop.
Save mehdichaouch/1c4a61486553bb257a2a4be4c3ed1ec8 to your computer and use it in GitHub Desktop.
Magento - jQuery function to sort configurable product attribute options by value
jQuery.fn.sortOptionsByValue = function(){
jQuery(this).each(function(){
var op = jQuery(this).children("option");
op.sort(function(a, b) {
return a.value > b.value ? 1 : -1;
});
return jQuery(this).empty().append(op).val('').attr({selected: 'selected'});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment