views:

92

answers:

1

Hi,

I want to insert an Element at the position bottom -1 of his parent.

The following code insert at the bottom

el.insert({bottom: content})

thanks

+1  A: 

You can insert it "before the last child element" like this:

el.select('*').last().insert({before:content});

el.select('*') gives the child elements in a nice prototype-extended collection.

last() of course retrieves the last element of that collection. You might want to retrieve it separately and make sure it is not undefined (which is what will be returned if there are no children) before attempting to "insert before it".

Also, IMO it feels better to pass in a non-wildcard selector if possible. For example, when the containing element is an <ul>, pass in 'li'.

Links:
Prototype Element#insert
Prototype Array#last

npup
Does insert still work in Prototype 1.6? Can't find it in the retardedly-organized new API doc.
dalbaeb
Yeah sure, it's a corner stone in the Prototype DOM API I think. Look here: http://api.prototypejs.org/dom/element/insert/
npup