I am trying to add a node after the first child node as well as after the last child node of body tag.
I tried it in jsfiddle.com: http://jsfiddle.net/satishkmr/7MM52/3/
A condition is checked in between for text node.
if(nextSibOfRefElem.nodeType == 3 )
{
nextSibOfRefElem = nextSibOfRefElem.nextSibling
alert(nextSibOfRefElem.innerHTML)
}
But in case of adding last child node of body, it does not interpret after the if condition(line no. 7 of javascript section). But while commenting out the if condition it works i.e. it gets appended to the last node. What is wrong with the if condition when nextSibling is null. Please help to sort it out.