Javascript DOM HTML UL Object get

Introduction

The Ul object represents an HTML <ul> element.

We can access a <ul> element via document.getElementById():

var x = document.getElementById("myUL");

Click the button to get the id of the unordered list.

View in separate window

<!DOCTYPE html>
<html>
<body>

<ul id="myUL">
  <li>CSS</li>
  <li>HTML</li>
  <li>Java</li>
</ul>/*from   w w w  .j  ava  2s . c  o m*/
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myUL").id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related