Javascript DOM HTML UL copy <LI> item

Description

Javascript DOM HTML UL copy <LI> item

View in separate window

<!DOCTYPE html>
<html>
<body>

<ul id="myList1"><li>CSS</li><li>HTML</li></ul>
<ul id="myList2"><li>SQL</li><li>Java</li></ul>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {//from www .  j a  v  a 2s.  c  om
  var itm = document.getElementById("myList2").lastChild;
  var cln = itm.cloneNode(true);
  document.getElementById("myList1").appendChild(cln);
}
</script>

</body>
</html>



PreviousNext

Related