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

  • Home
  • SEARCH
  • 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 9182545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:35:05+00:00 2026-06-17T18:35:05+00:00

I want to bind classes to a div based on a dynamic value in

  • 0

I want to bind classes to a div based on a dynamic value in ember; it should hide the DOM element when it is false and add two classes to it when the value is true.

Here is my code:

<div {{bindAttr class="App.User.isLoggedIn:alert alert-error:hide" }} >
    ...
</div>

However the bindings don’t work and it keeps showing the div even when app.User.isLoggedIn is false.

How do you bind multiple classes based on a true condition?

  • 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-17T18:35:06+00:00Added an answer on June 17, 2026 at 6:35 pm

    So, to get a mix of bound attributes (in your case, class names), you can list separate the binding criteria with spaces.

    Basically, in your {{bindAttr …}} helper, you can write boundAttr=”criterion1 criterion2 criterion3″, where the individual binding criterion expand out to the following format:

    Property substitution

    propertyName
    

    This stubs in classNames with two different behaviours:

    1. if the property value is a boolean: the dasherized property name
    2. if the property value is a string: the string value

    Static class/Always true:

    :className
    

    Always adds the classname to the div.

    Conditional on an property:

    propertyName:trueClass 
    propertyName:trueClass:falseClass 
    propertyName::falseClass
    

    Evaluates the property, and assigns the appropriate class based on truthy/falsy values.

    In your case, since you want to have two classes hanging off the same property, you could do:

    <div {{bindAttr class="App.User.isLoggedIn:alert App.User.isLoggedIn:alert-error:hide"}} >
        ...
    </div>
    

    Note the spaces here. The first criterion takes care of just the alert class, while the second takes care of the ‘alert-error’ or ‘hide’ classes accordingly.

    If you wanted something even simpler, you could have a calculated property that determines the string you need to apply in your view or model.

    Then you could do

    // in your view
    classesNeeded: function() {
    
       return App.User.get('isLoggedIn') ? 'alert alert-error' : 'hide';
    
    }.property('App.User.isLoggedIn')
    

    And then:

    <div {{bindAttr class="view.classesNeeded"}} >
            ...
        </div>
    

    In the hypothetical case where you needed a third, default class for all cases, you could do:

    <div {{bindAttr class=":defaultClass view.classesNeeded"}} >
            ...
        </div>
    

    You can read up more on attribute and class bindings in the new ember.js doc, here:
    http://emberjs.com/guides/templates/binding-element-class-names/

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

Sidebar

Related Questions

I want to bind a click event with the element: $('a').click(function(){ btn_submit_pressed=false; }); Now,
I want to bind a string value to a text box but only if
I want to bind to a value in a dictionary property of an object.
I want to bind class of LI/DIV. I'm using knockout.js. I don't know how
I want to bind columns in a DataGridView to pull values from two different
I want to bind a function to an event but I want to change
I want to bind Groupboxes to my stackpanel. c#: internal ObservableCollection<GroupBox> BindingTest { get
I want to bind my ListView control to a generic list of objects? I
I want to bind Ctrl-Alt-N to an External Tool (Nant build) in SharpDevelop, how
I want to bind an event to a certain class and ID for when

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.