A Pen by Willy Aguirre on CodePen.
Created
May 19, 2014 20:35
-
-
Save marti1125/1c95db15410ef380115b to your computer and use it in GitHub Desktop.
A Pen by Willy Aguirre.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="visLines" class="channel-visualisation subscription-channels"> | |
<div class="channel" color="blue" for="sendMessage" data-val="4"> | |
4 | |
<div class="dot color"></div> | |
</div> | |
<div class="channel" color="pink" for="clear" data-val="3"> | |
3 | |
<div class="dot color"></div> | |
</div> | |
<div class="channel" color="red" for="set_room" data-val="2"> | |
2 | |
<div class="dot color"></div> | |
</div> | |
<div class="channel" color="purple" for="set_username" data-val="1"> | |
1 | |
<div class="dot color"></div> | |
</div> | |
</div> | |
<a href="#" id="sortElements">Sort</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sortElements = document.getElementById("sortElements"); | |
var visLines = document.getElementById("visLines").getElementsByTagName('div'); | |
var visLines2 = document.getElementById("visLines") | |
var elements = []; | |
var divs = []; | |
sortElements.addEventListener("click", function( event ) { | |
elements = []; | |
divs = []; | |
for(i=0; i< visLines.length; i++){ | |
if(visLines[i].getAttribute("data-val") != null){ | |
elements.push(visLines[i].getAttribute("data-val")); | |
} | |
} | |
elements.sort() | |
for(i=0; i< elements.length; i++){ | |
divs.push(visLines2.querySelector('[data-val="' + elements[i] + '"]')); | |
} | |
document.getElementById("visLines").innerHTML = ""; | |
for(i=0; i< divs.length; i++){ | |
document.getElementById("visLines").innerHTML += divs[i].outerHTML; | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment