actually more like this, strictly following the required outcome...
Code:
<script>
$($('div[class*=" x"]').not($('div[class*=" x"]:last')).get().reverse()).each(function() {
$(this).attr("class","changed")
$('div[class*=" x"]:last').prepend($(this));
});
</script>