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.
value |
Yes | Yes | Yes | Yes | Yes |
Return the value property:
var v = liObject.value
Set the value property:
liObject.value = number.
Value | Description |
---|---|
number | Specifies the value of the list item |
A number representing the value of the list item.
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:
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: