<div id="container">
<div class="row">
<div class="name">Player1</div><div class="score">430</div>
</div>
<div class="row">
<div class="name">Player2</div><div class="score">580</div>
</div>
<div class="row">
<div class="name">Player3</div><div class="score">310</div>
</div>
<div class="row">
<div class="name">Player4</div><div class="score">640</div>
</div>
<div class="row">
<div class="name">Player5</div><div class="score">495</div>
</div>
</div>
<style>
#container {
width: 600px;
height: auto;
}
.row {
position: relative;
display: block;
width: 100%;
height: 40px;
border-bottom: 1px solid #AFAFAF;
}
.name {
position: relative;
display: inline-block;
width: 75%;
line-height: 45px;
}
.score {
position: relative;
display: inline-block;
width: 25%;
}
.row:nth-child(1) {
background: gold;
}
.row:nth-child(2) {
background: #c0c0c0;
}
.row:nth-child(3) {
background: #cd7f32;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
let elements = []
let container = document.querySelector('#container')
// Add each row to the array
container.querySelectorAll('.row').forEach(el => elements.push(el))
// Clear the container
container.innerHTML = ''
// Sort the array from highest to lowest
elements.sort((a, b) => b.querySelector('.score').textContent - a.querySelector('.score').textContent)
// Put the elements back into the container
elements.forEach(e => container.appendChild(e))
});
</script>
Code Example |
---|
Html :: html text |
Html :: html circle symbol |
Html :: v-tabs |
Html :: laravel turn excel into html table |
Html :: table label html |
Html :: symfony twig form value |
Html :: html heading tags |
Html :: input text before element |
Html :: run script after html load |
Html :: html color input |
Html :: html input name and value and id |
Html :: include react in html |
Html :: create custum tage html |
Html :: loader |
Html :: angular html variable |
Html :: what is the html command |
Html :: latex in html |
Html :: ubuntu 17.10 vmware |
Html :: add output buffering to cagefs |
Html :: html multi like tag indentation convention |
Html :: horizontal news ticker |
Html :: equipages meaning |
Html :: Search CSV files for text |
Html :: nigeria naira code |
Html :: svm e1071 cutoff |
Html :: navratri 2020 |
Html :: how to alert in http |
Html :: lpluguin de whatsapp para html |
Html :: html peseta symbol |
Html :: how to make my html website resize a iphone |