0

I want to conditionally add a ID attribute to the div tag


I tried something like this

 <div class="row" data-bind="attr: { id:'selectedReplyMessage': $component.selectedReplyMessageID() == _id }"></div>

But it didnt work

Although this code

<div class="row" data-bind=" css:{selectedReplyMessage: $component.selectedReplyMessageID() == _id }">

is working completely fine.But i want to associate ID with the component.

manish kumar
  • 4,412
  • 4
  • 34
  • 51

1 Answers1

0

As mentioned by Adigo

 <div class="row" data-bind="attr: { id: $component.selectedReplyMessageID() == _id ? 'selectedReplyMessage' : null }"></div>

Doing like this way you can acheive you desired output.Using ternary operator and putting the values.

manish kumar
  • 4,412
  • 4
  • 34
  • 51