Quantcast
Channel: w3mentor » Javascript
Viewing all articles
Browse latest Browse all 100

Replace DOM nodes using Javascript

$
0
0
<script language="JavaScript" type="text/JavaScript"> var nr = 1; function addItem() { var list = document.getElementById("list"); var newNode = document.createElement("li"); nr++; var newTextNode = document.createTextNode("Item " + nr); newNode.appendChild(newTextNode); list.replaceChild(newNode, list.firstChild); } </script> <ul id="list"><li>Item 1</li></ul> <input type="button" onclick="addItem();" value="Replace item" />
Continue reading...

Viewing all articles
Browse latest Browse all 100

Trending Articles