TypeError: Element.insert is not a function

I followed this railscast to add "complex" functionality to a form. I added the ability to click a link to add an element to an object form and a link to remove it.

However I am getting this error when I click "add element"

RJS error:

TypeError: Element.insert is not a function

and then

Element.insert("docs", { bottom: "<div class=\"doc\">\n\n Doc: <input .....etc

try to add <%= javascript_include_tag :defaults %> in your layout file

thanks for the suggestion. It's already in the layout file, any other ideas?

Thanks for the answer, I included <%= javascript_include_tag :defaults %> and it worked!

I recently overhauled pages for speed improvements including creating cached pages for my styles and javascript files and ended up with the same error. I performed diffs on my /public directories and found that my true.js file had concatenated file that was contained in another cached file. In other words, I had the same .js file being called twice. When I removed the duplicate, my error disappeared and my form worked properly.

Good luck!

I bumped into another problem made apparent using the horrible IE 7 browser. A javascript error showing there (but not in Firefox) led me to a code error in an outside vendor widget. Removing the code also stopped a seemingly unrelated error.

You might consider removing all your .js files except the one that seems to throw the error. Adding your .js files one at a time might lead you to the problem file.