Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort li elements with js

const ul = document.querySelector('ul');
const liElements = Array.from(document.querySelectorAll('li')); //creating array from the li elements

//Sorting the li elements by text content Asc order
liElements.sort((li1,li2) => li1.textContent.localeCompare(li2.textContent));

//Append the sorted li elemtns into the ul 
appendCh(liElements,ul)

//Function that will append them all
function appendCh(liArr,parent){
  
        liArr.forEach(el => {
            parent.appendChild(el);
        })
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: merge sort algorithm in javascript 
Javascript :: js create element with class 
Javascript :: mongoose save or update 
Javascript :: TypeError: Class constructor Model cannot be invoked without 
Javascript :: on focus out javascript 
Javascript :: reverse json.stringify 
Javascript :: extract value from object javascript 
Javascript :: how to show selected value in select box using jquery 
Javascript :: js seconds to time 
Javascript :: how to write a json in r 
Javascript :: js object keys 
Javascript :: dynamically added button onclick not working 
Javascript :: window.cookies javascript 
Javascript :: convert timestamp to time javascript 
Javascript :: javascript typewriter effect 
Javascript :: jquery loop 0 to 10 
Javascript :: change js 
Javascript :: A bad HTTP response code (404) was received when fetching the script. 
Javascript :: javascript find object array 
Javascript :: remove comma from end of string javascript 
Javascript :: remove value from input jquery 
Javascript :: js password check 
Javascript :: export default react 
Javascript :: how to auto refresh page in javascript 
Javascript :: react bootstrap col not working 
Javascript :: no special characters express validator 
Javascript :: node-fetch 
Javascript :: setinterval javascript 
Javascript :: ** javascript 
Javascript :: usecontext react 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =