HTML Binding in Knockout

Same as text binding in knockout html binding works although it can render HTML elements too with data into it.

Secret of working : It uses javascript innerHTML function to bind html markup.

Let’s look at example of it.

Simple example:

We have stockMessage as knockout observable with initial value italic HTML element “In stock” which changes later to out of stock with bold element.

Another Example with condition of quantity:
If item quantity is less than 10 we displays out of stock message in bold and if not than in stock message in italic.

We have bind html markup elements using knockout.

Leave a Reply