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

Updating a view's element class attribute

In the previous section, we learned that views are usually wrapped in a configurable DOM element. The element's class attribute can also be specified statically using the view's classNames array property. For example, a Twitter Bootstrap button can be created as:

var view = Ember.View.extend({
  tagName: 'button',
  classNames: ['btn', 'btn-primary]
});

This will yield something like the following:

<button class='btn btn-primary'>Button</button>

The element's classes can also be altered dynamically using the view's classNameBindings array property, as shown in the following code:

var View = Ember.View.extend({
  tagName: 'button',
  classNames: ['btn'],
  classNameBindings: ['btnWarning'],
  btnWarning: true
});

This example ...

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