Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Latest commit

 

History

History
27 lines (19 loc) · 788 Bytes

injection.md

File metadata and controls

27 lines (19 loc) · 788 Bytes

DOM injection

Once you have assembled and rendered your View you'll want to inject it into the DOM at some point. FruitMachine has multiple ways of doing this:

  • .inject(<Element>) Empties the contents of the given element, then appends view.el.
  • .appendTo(<Element>) Appends view.el to the given Element.
  • .insertBefore(<Element>, <Element>) Appends view.el to the given Element as a previous sibling of the second Element parameter.

View#inject()

var container = document.querySelector('.container');
var apple = new Apple();

apple.render();
apple.inject(container);

View#appendTo()

var list = document.querySelector('.list');
var apple = new Apple();

apple.render();
apple.appendTo(list);