I am trying to convert my jQuery script into javascript. I have a problem there..
I have a script that creates a node
var new_node = document.createElement("div");
new_node.className="tooltip";
new_node.innerHTML = html;
alert(new_node.className);
When i do this
jQuery(link).after(new_node);
It works fine. But I want to do it javascript way. I have tried using appendChild function but it gives some strange results.
Please help me out with this.
You're comparing jQuery's
afterwithappendChild, but they do very different things.afterputs the element after the reference element,appendChildputs it inside it.You probably want
insertBefore(with the reference node beinglink'snextSibling).So:
If
linkis the last thing in its parent, that's fine;link.nextSiblingwill benullandinsertBeforeacceptsnullas the reference node (it means "insert at the end").