I think you may be getting mislead by how the result looks:
Test
hi
That makes it look like they're stacked, but they're not, your code is working fine. The second div is inside the first, after the text.
Adding borders and padding can make that clearer:
window.onload = function() {
var child = document.createElement('div');
child.id = 'blockid';
child.className = 'blockclass';
var s = document.getElementById('parent');
s.appendChild(child);
document.getElementById("blockid").innerHTML = "hi";
};
#parent {
border: 1px solid blue;
padding: 4px;
}
#blockid {
border: 1px solid green;
}
<div id="parent">Test</div>
Note, though, that you don't need the document.getElementById at the end, you can use child:
window.onload = function() {
var child = document.createElement('div');
child.id = 'blockid';
child.className = 'blockclass';
var s = document.getElementById('parent');
s.appendChild(child);
child.innerHTML = "hi"; // <== Changed
};
#parent {
border: 1px solid blue;
padding: 4px;
}
#blockid {
border: 1px solid green;
}
<div id="parent">Test</div>
blockidis inserted insideparent. Do you expectparentto cinain only the div and notHianymore ?document.getElementById, just usechild). So we need more information to be able to help you.