How do I use Node.insertBefore to add content to a specific node
I am trying to add a string variable as a child of开发者_开发知识库 a node. The code that I'm using looks like this
$(this).parentNode.parentNode.insertBefore('content',$(this).parentNode)
I believe that this is correct syntax, but I keep receiving NOT_FOUND_ERR: DOM Exception 8. Does anyone have any pointers?
parentElement.insertBefore(el, beforeWhat);
if you want to insert a new element BEFORE a node
if you want to append a new textNode to the element you rather need
var textNode = document.createTextNode("content");
el.appendChild(textNode);
but what really bothers me is that you seem to using jQuery or some framework, and use DOM methods on them. Because that won't work.
You need to use their own methods then, like:
$(this).append("content");
精彩评论