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


JAVASCRIPT DHTML TUTORIALS » Node Operation » firstChild »

 

'firstChild' 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("myL").firstChild;
    document.getElementById("myL").replaceChild(newI, fLi);
}

function function2(form) {
    var newI = newElem(form.enter.value);
    var fLi = document.getElementById("myL").lastChild;
    document.getElementById("myL").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="myL"><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
» firstChild