DOM .lastChild
So have you read any other DOM method tutorials yet ? If not thats ok.
In this tutorial we are talking about .lastChild
So if you have read the .parentNode and/or .firstChild tutorial already. its roughly the same! You can pretty much guess what it does. It grabs the last child(element) of the div or table tag.
Lets look at an example:
<div id=”parent”>
<div >first</div>
<div >second</div>
<div >third</div>
<div >fourth</div>
</div>
so what we have here is some div tags. 1 parent Div and 4 child divs.
so here is how we could use the .lastChild DOM element.
document.getElementByID(“parent”);
first you want to call the ID ( I am using an ID for easy understanding. you won’t always have ID’s to work with.) Once you have that ID called in a variable or what not. you can use .lastChild
document.getElementByID(“parent”).lastChild;
What that just did was call the Last (Child) Div tag.
<div >fourth</div>
that one :P
from there you can use innerHTML or use more DOM if there are more elements inside that tag.
Look in the Tutorials for more DOM methods!
