O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inserting views into DOM

We just learned that views have templates that they render into DOM. Applications that need to do this manually will need to utilize the view instance appendTo method, as shown in the following example:

view.appendTo('#header');

This method takes a jQuery query selector that we are already used to, as shown in the following examples:

view.appendTo('header');
view.appendTo('#header');
view.appendTo('.header');
view.appendTo('body > header');

Note that only one matched element is used. Therefore, in the third example, the view will be inserted into the last header element found.

As a convenience, views have an append method that can be used to insert the views directly into the body section of DOM:

view.append(); // appends view ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required