Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:34:27+00:00 2026-06-12T22:34:27+00:00

As mentioned in @andorov’s answer , the OP’s ideal code ( <div style=width:{{model.width}}> now

  • 0

As mentioned in @andorov’s answer, the OP’s ideal code (<div style="width:{{model.width}}"> now pretty much just works as of Ember 1.10

I am new to Ember.js, and I am finding it difficult to dynamically
change CSS. Here is an example to explain what I mean:

var App = Em.Application.create();

App.MyObj=Em.Object.extend({
    objWidth:10
});

App.objController = Ember.ArrayController.create({
    content: [],
  createObj: function(){
      var obj = App.MyObj.create();
      this.pushObject(obj);
  }
});

The code below doesn’t work, but it explains my goal. Using a
Handlebars template, I want to accomplish this:

{{#each obj in App.objController}}
     <div style="width:{{obj.objWidth}}"></div>
{{/each}}

In other words, I just want to have the width of the <div> update
when the objWidth property is changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:34:28+00:00Added an answer on June 12, 2026 at 10:34 pm

    The style property has to be bound with bindAttr, passing the style as a whole, not just one of the properties, as it doesn’t understand that. This property only gives you access to the style as a string, targeting the immediate element. It’s not possible to bind to a property of the style if you define it like that.

    So here’s my sugestion: I’ve created a couple of “model” classes like the following, implementing a property that returns the width in pixels:

    var WidthEnabledModel = Em.Object.extend({
        width: 100,
        unit: "px",
        widthString: function() {
            return 'width: %@%@'.fmt(this.width, this.unit);
        }.property('width', 'unit')            
    });
    
    App.SampleModel = WidthEnabledModel.extend({
        itemName: ''
    });
    

    Then, for each item in your collection I’m binding that property to the style attribute:

    <script type="text/x-handlebars" data-template-name="sample">
        <div id="sample_area" style="width: 250px;">
        {{#each thing in controller.content}}
          <div class="item" {{bindAttr style="thing.widthString"}}>
              {{thing.itemName}}<br />
              {{thing.widthString}}
          </div>
        {{/each}}
        <div>
    </script>
    

    Follow the example with full code I’ve made at jsfiddle here http://jsfiddle.net/schawaska/ftWZ6/

    Edit:
    I’ve made some changes in the fiddle to add more feature, but the part to set the width stays the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As mentioned in this answer simply calling the destructor for the second time is
As mentioned elsewhere , this code has the potential for a race condition: //
I have the below mentioned code in a seperate class file for establishing connection
As mentioned below I have made changes to the code which looks like following
As mentioned above. Here's a snippet: $model=SomeModel::model()->findByPk($someId); $model->email = $_POST['email']; $model->save(); When $_POST['email'] is
As mentioned in an earlier question , I have uncovered some style options that
As mentioned in the question, and the following shows mu code .. AlarmActivity package
As mentioned in one of the comments in an answer below, I tried following
as mentioned in some other threads i'm a having trouble to setText inside a
somebody mentioned that the function (in this case a method) below is no good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.