The goal
Pass to the DOM strings with HTML and render it.
The scenario
I'm extending properties of an observable (with KnockoutJS) using the follow syntax:
self.showDetails.subscribe(function (context) {
var details = this.showDetails();
details.nameWithCnpj = context.name() + " <small>" + context.cnpj() + "</small>";
}, this);
If you pay attention on the following line, you can see the HTML on it:
details.nameWithCnpj = context.name() + " <small>" + context.cnpj() + "</small>";
When the <small></small> tag arrives on the HTML, it is rendered as string instead of vanilla HTML.
The container that houses the nameWithCnpj (using KnockoutJS) is the following:
<h2 class="bold float-left" data-bind="text: nameWithCnpj"></h2>
So I ask: How can I teach to JavaScript (or HTML) that the nameWithCnpj variable should be a DOM element instead of a simple string?
nameWithCnpj, please post the code where you display the content ofnameWithCnpj!htmlbinding instead oftext? (Just for curiosity)