views:

41

answers:

1

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?

A: 
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");
galambalazs
@galambalazs, I was too quick to call you out, I apologize for that. It turned out that prototype was overriding the $() operator so when I thought I was using jQuery, it was actually prototype which is why non of the methods I tried were working. To use the two together I put var $j = jQuery.noConflict() at the top of my application.js file
Teddy
Yeah my instinct was somewhat right then. Glad you've solved it. :)
galambalazs