I am dynamically adding Child DIVs to a Parent DIV, but appendChild() inserts the new child DIV at the end and I want new insertions to be at the top. I understand inserBefore(), but initially there are no children in the DIV. Is ther an easy way to do this?

Member Avatar for diafol

Check to see if parent node is empty. IF so add, is not "prepend" using insertBefore, e.g. using:

if (!element.hasChildNodes()) 
{
    //add
}else{
    //prepend
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.