JSFiddle - React, Tailwind, and code Playground
by gunderson
HTML
<div><span class="chosenword" order="1">Word 1</span> -
<span class="chosenword" order="550">Word 550</span> -
<span class="chosenword" order="57">Word 57</span>
</div> -
<div id="chosenwords"></div>
JavaScript
$('.chosenword').sort(sortByIdAttr).each(function() {
var chosenword = $(this).html() + " - ";
$('#chosenwords').append(chosenword);
});
function sortByIdAttr(a, b) {
var idA = parseInt($(a).attr('order'));
var idB = parseInt($(b).attr('order'));
if (idA < idB) {
return -1;
} else {
return 1
}
}