JavaScript:

Prototype element insert example

1

If you’re like me, you found the documentation on prototype’s insert method lacking much needed documentation http://www.prototypejs.org/api/element/insert . They say the format is like

insert(element, { position: content }) -> HTMLElement

What the heck does that mean? Obviously you can’t just paste it in because it’ll cause a JavaScript error. After some googling and trial and error, I have the code working and will provide it as an example. The code create a div with content and places it at the bottom of an existing page element.

//create new div
var myDiv = new Element( 'div' );
 
//put product name in the new div
myDiv.update('text inside the div');
 
//append div to page element
Element.insert($('pageElement'), {'bottom':myDiv} );
Posted in: JavaScript

Continue Reading