Last active
November 13, 2023 09:24
-
-
Save maxout/2ab036d233c033186416 to your computer and use it in GitHub Desktop.
jQuery sort clothing sizes in select box for shopware configurator articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var sizes = ["XS", "S", "M", "L", "XL", "2XL", "3XL", "4XL"], | |
select = $('.configurator--form select[name="group[2]"]'); | |
$('option', select).sort(function (a, b) { | |
if(isNaN($(a).text().trim())){ | |
return sizes.indexOf($(a).text().trim()) - sizes.indexOf($(b).text().trim()); | |
}else{ | |
return $(a).text() > $(b).text() ? 1 : $(a).text() < $(b).text() ? -1 : 0; | |
} | |
}).appendTo(select); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment