javascript - How to sort a html -


we wanted sort following html using javascript:

<fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="32gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">32gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="16gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">16gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="128gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">128gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="64gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">64gb</span></label></fieldset> 

to this:

<fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="16gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">`16gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="32gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">32gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="64gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">64gb</span></label></fieldset> <fieldset class=""><input type="radio" name="devicestorage" id="storage3" value="128gb" class="storage-option device-storage3"/><label for="storage3" class="device-storage-label"><span class="big-size">128gb</span></label></fieldset> 

how can achieve this?

<!doctype html>  <html>  <body>    <p>click button sort array.</p>    <button onclick="myfunction()">try it</button>    <p id="demo"></p>    <script>  var fruits = ["32gb", "16gb", "128gb", "64gb"];  document.getelementbyid("demo").innerhtml = fruits;    function myfunction() {      fruits.sort();      fruits.sort(function(a, b){return a.length-b.length});      document.getelementbyid("demo").innerhtml = fruits;  }  </script>    </body>  </html>


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -