Javascript Reference - HTML DOM Style order Property








The order property gets and sets the order of a flexible item relative to other the flexible items inside the container.

Browser Support

Style order Yes No Yes No Yes

Syntax

Return the order property:

var v = object.style.order ;

Set the order property:

object.style.order='number|initial|inherit'




Property Values

Value Description
number Default value 0. Set the order for the flexible item
initial Set to default value.
inherit Inherit from parent element.

Technical Details

Default Value: 0
Return Value: A string representing the order property
CSS Version CSS3




Example

The following code shows how to set the order of the flexible items.


<!DOCTYPE html>
<html>
<head>
<style> 
#main {<!--from  ww  w . ja va  2  s .  c  o m-->
    width: 400px;
    height: 150px;
    border: 1px solid #000000;
    display: flex;
}

#main div {
    width: 70px;
    height: 70px;
}
</style>
</head>
<body>
<div id="main">
  <div style="background-color:coral;" id="myRedDIV"></div>
  <div style="background-color:lightblue;" id="myBlueDIV"></div>
  <div style="background-color:lightgreen;" id="myGreenDIV"></div>
  <div style="background-color:pink;" id="myPinkDIV"></div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myRedDIV").style.order = "4";
    document.getElementById("myBlueDIV").style.order = "3";
    document.getElementById("myGreenDIV").style.order = "1";
    document.getElementById("myPinkDIV").style.order = "2";
}
</script>
</body>
</html>

The code above is rendered as follows: