'lastChild' Example : lastChild : Node Operation JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Node Operation » lastChild »

 

'lastChild' Example



    
<html>
<body>
<script language="JavaScript">
function newElem(myT) {
    var newI = document.createElement("LI")
    newI.innerHTML = myT
    return newI}
function function1(form) {
    var newI = newElem(form.enter.value);
    var fLi = document.getElementById("myList").firstChild;
    document.getElementById("myList").replaceChild(newI, fLi);}
function function2(form) {
    var newI = newElem(form.enter.value);
    var fLi = document.getElementById("myList").lastChild;
    document.getElementById("myList").replaceChild(newI, fLi);}
</script>

<form>
<input type="text" name="enter" size="50">
<button onClick="function1(this.form);"> Replace first item</button>
<button onClick="function2(this.form);"> Replace last item</button>

<ul id="myList">
    <li>First List Item</li>
    <li>Second List Item</li>
</ul>

</form>
</body>
</html>

    
      
      



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Node Operation
» lastChild