So my question is it possible to sort list items by number in strong tag, when i try with JavaScript code below it sort numbers and but get them out of div tag. (I use these js code for sorting by Name and it work fine when b = ...(LI)) HTML:
<section>
<button class="sortbynum" onclick="sortListNum()">Sort By Num</button>
<ul id="sort">
<li>
<div><h2>Name</h2></div>
<a href=""><img src=""/></a>
<div><span>Something:...</span></div>
<div><span>something:...</span></div>
<div><span>HHJS: <strong class="sortNum">456</strong></span></div>
</li>
<li>again</li>
</ul>
JavaScript:
function sortListNum() {var list, i, switching, b, shouldSwitch, dir,switchcount = 0;list = document.getElementById("sort");switching = true;dir = "asc"; while (switching) {switching = false;b = list.getElementsByClassName("sortNum");
for (i = 0; i < (b.length - 1); i++) {
shouldSwitch = false;
if (dir == "asc") {
if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) {
shouldSwitch= true;
break;
}
} else if (dir == "desc") {
if (b[i].innerHTML.toLowerCase() < b[i + 1].innerHTML.toLowerCase()) {
shouldSwitch= true;
break;
}
}
}
if (shouldSwitch) {
b[i].parentNode.insertBefore(b[i + 1], b[i]);
switching = true;
switchcount ++;
} else {
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}}}