How to set the order of the flexible item, relative to the rest with JavaScript?


To set the order of the flexible item, relative to the rest of JavaScript, use the order property. You can try to run the following code to implement order property −

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            border: 1px solid #000000;
            width: 420px;
            height: 150px;
            display: flex;
         }
         #box div {
            height: 80px;
            width: 80px;
         }
      </style>
   </head>
   
   <body>
      <div id = "box">
      <div style = "background-color:orange;" ID ="myID1">DIV1</div>
      <div style = "background-color:blue;" id = "myID2">DIV2</div>
      <div style = "background-color:yellow;" id = "myID3">DIV3</div>
      </div>

      <button onclick = "display()">Set</button>

      <script>
         function display() {
            document.getElementById("myID1").style.order = "3";
            document.getElementById("myID2").style.order = "1";
            document.getElementById("myID3").style.order = "2";
         }
      </script>
   </body>
   
</html>

Updated on: 30-Jul-2019

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements