Element content

When manipulating element content in Aurelia, you have several options at your disposal. Let's explore how to bind values to innerHTML, textContent, and more.

In the previous section on text interpolation, we showed how you can use interpolation to display values, which is the equivalent of binding to the textContent property.

Using textContent Binding

For more control, you can bind directly to textContent:

<p textcontent.bind="message"></p>

This is useful when you want to set the entire text content of an element.

HTML content binding

To bind HTML content, use the innerHTML attribute:

<div innerhtml.bind="htmlContent"></div>

Controlling text direction

<p textcontent.bind="message" dir.bind="textDirection"></p>

In your view-model:

export class MyViewModel {
  message = "Hello, Aurelia!";
  textDirection = "rtl"; // or "ltr"
}

Raw HTML Binding

If you need to bind raw HTML and you're sure it's safe, Aurelia provides a innerhtml binding command:

Last updated

Was this helpful?