var firstDivID = document.getElementById("content").firstChild.id;
btw it’s best not to use firstChild because it might unexpectantly return a text node (which is not what you want).
A better way would be to find the first element within the div. So if you’re looking for a DIV within another DIV then:
var firstDivID = document.getElementById("content").getElementsByTagName('div')[0].id;
If you want to navigate the DOM using firstChild / childNodes[n] etc etc. then make sure when you use the referenced nodes, you check them first to make sure they’re what you expected.
For example to make sure “firstChild” is a div:
var firstDiv = document.getElementById("content").firstChild;
if( firstDiv.nodeName.toLowerCase()==="div" ) {
var firstDivID = firstDiv.id;
}
And if you’re looking for the first element but you don’t know what it might be, check the nodetype.
A value of 1 is an element, a value of 3 is a text node.
var firstEl = document.getElementById("content").firstChild;
while (firstEl.nodeType != 1) {
firstEl = firstEl.nextSibling;
}