Javascript DOM HTML Li value Property get

Introduction

Return the value of a list item:

var x = document.getElementById("myLi").value;

Click the "Test" button to display the value attribute of the li element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<ol>
  <li id="myLi" value="100">CSS</li>
  <li>HTML</li>
  <li>Java</li>
  <li>Javascript</li>
  <li>SQL</li>
  <li>C++</li>
</ol>/*from  ww w. j av a2 s  .  c  om*/
<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>



PreviousNext

Related