fbiville
fbiville

Reputation: 8960

Prototype 1.6.0.3 - "Insert is not a function"

I'm going berserk with this. Although http://www.prototypejs.org/api/element/insert is far from being the best documentation page ever, I struggle with a really stupid simple implementation:

$('account').insert({'top':new Element('a')});

I also tried with a plain HTML string instead of new Element(a), but it doesn't change anything... Can you spot what's wrong with what I'm doing ?

Upvotes: 1

Views: 2554

Answers (2)

Pointy
Pointy

Reputation: 413846

Prototype returns null from $("foo") if no element with "id" value "foo" is on the page. If you're using the "id" value "account" on multiple elements, anything might happen, so don't do that. Otherwise make sure there's an element with "id" value "account" on the page when that code runs.

Upvotes: 3

Dan Grossman
Dan Grossman

Reputation: 52372

In JavaScript, the semicolon terminates a statement. You don't want to terminate the statement there, you wanted to call .insert on the result of $('account'), so don't put a semicolon there.

According to the documentation you linked, you're also missing a set of curly braces and some quotes.

$('account').insert({'top': new Element('a')});

Upvotes: 0

Related Questions