开发者

Element.insert at bottom-1 with prototype

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

The 开发者_Go百科following code insert at the bottom

el.insert({bottom: content})

thanks


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜