Javascript Reference - HTML DOM Li value Property








The value attribute sets the value of a list item, and the list items after will increment from that value.

The value property sets or gets the value of the value attribute of a list item.

The value must be a number and can only be used in <ol> element.

Browser Support

value Yes Yes Yes Yes Yes

Syntax

Return the value property:

var v = liObject.value

Set the value property:

liObject.value = number.




Property Values

Value Description
number Specifies the value of the list item

Return Value

A number representing the value of the list item.

Example

The following code shows how to set the list items to increment from the number "2".


<!DOCTYPE html>
<html>
<body>
<ol>
  <li id="myLi">A</li>
  <li>B</li>
  <li>C</li>
  <li>D</li>
  <li>E</li>
  <li>F</li>
</ol><!--from   w  ww. j  ava 2s.  co m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myLi").value = "2";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the value of a list item.


<!DOCTYPE html>
<html>
<body>
<ol>
  <li id="myLi" value="100">A</li>
  <li>B</li>
  <li>C</li>
  <li>D</li>
  <li>E</li>
  <li>F</li>
</ol><!--from   w  w  w . jav  a  2s.co  m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myLi").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows: