JSFiddle - React, Tailwind, and code Playground
HTML
<div style="z-index: 10" id="foo">Foo</div>
<div style="z-index: 0" id="bar">Bar</div>
<div style="z-index: 1000" id="foz">Foz</div>
<div style="z-index: 50" id="baz">Baz</div>
<div style="z-index: 30" id="bat">Bat</div>
CSS
div {
width: 100px;
height: 100px;
position: absolute;
}
JavaScript
var sortByZIndex = function(a, b) {
return a.style.zIndex - b.style.zIndex;
}
var sorted = $('div').sort(sortByZIndex);
alert("Sorted: " + $.map(sorted, function(e){ return e.id; }).join(', '));