Search code examples
ajaxprototypejsinsertion

Insert Ajax.Updater content before specific element using insertion parameter


I thought this would be fairly simple but it turns out not to work as I thought it would or should.

new Ajax.Updater('myContainer','/url/',{
   insertion: {before: 'anotherElementId'}
});

How is this done correctly?


Solution

  • As stated in the docs for Ajax.Updater:

    The insertion option takes one of four strings — top, bottom, before, or after

    You are passing an object literal, which is why it does not work. The element referred to by the first argument to Ajax.Updater is the one which will be modified. That's the whole idea of that method (as a shorthand instead of doing the insert manually in a normal AJAX request callback).

    So I think what you were aiming for was this:

    new Ajax.Updater('anotherElementId','/url/',{
       insertion: 'before'
    });