How do I set an element's class using data-win-bind
Asked Answered
C

1

12

I'm trying to dynamically set the class of a listview item template:

<div id="semanticZoomTemplate" data-win-control="WinJS.Binding.Template" style="display: none">
    <h1 class="semanticZoomItem-Text" data-win-bind="innerText:title;class:contains"></h1>
</div>

But data-win-bind fails to do anything when 'class' is present as a property-name.

Is there a correct way to styling specific items in a listview if indeed I can't change the class with data-win-bind?

Crowded answered 17/5, 2012 at 20:46 Comment(0)
F
15

You need to set the JavaScript class property, which is not called "class", but "className".

Follicle answered 18/5, 2012 at 6:56 Comment(3)
Thanks! data-win-bind="innerText:title;className:contains" works great.Crowded
Hi @ChristiaanV, do you know if using class="other" data-win-bind="className:contains" replaces the class attribute or appends the binding to the existing?Brainwork
By default it overrides the "other" class. I know that you can build converters, which you can add in your binding, but don't know exactly if you can build a converter that can make the class append.Follicle

© 2022 - 2024 — McMap. All rights reserved.