Javascript Reference - HTML DOM Ol reversed Property








The reversed property sets or gets whether the list order should be reversed. For example, instead of 1, 2 , 3... it would be 3, 2, 1.

Browser Support

reversed Yes No Yes Yes Yes

Syntax

Return the reversed property.

var v = olObject.reversed

Set the reversed property.

olObject.reversed=true|false




Property Values

Value Description
true|false true - The list order is descending
false - Default. The list order is ascending.

Return Value

A Boolean type value, true if the list order is descending, otherwise it returns false.

Example

The following code shows how to Set the list order to descending.


<!DOCTYPE html>
<html>
<body>
<ol id="myOl">
  <li>A</li>
  <li>B</li>
  <li>C</li>
  <li>D</li>
  <li>E</li>
</ol><!--from w w w . j a v a  2 s  . c  o m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myOl").reversed = true;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to check if the list order is descending.


<!DOCTYPE html>
<html>
<body>
<!--from  ww  w  .java2 s  . co m-->
<ol id="myOl">
  <li>A</li>
  <li>B</li>
  <li>C</li>
  <li>D</li>
  <li>E</li>
</ol>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myOl").reversed;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows: