x-text & x-html
x-text
x-text sets the text content of an element to the result of a given expression.
Here's a basic example of using x-text to display a user's username:
html
<div x-data="{ username: 'pirate dev' }">
Username: <strong x-text="username"></strong>
</div>Now the
<strong>tag's inner text content will be set to "pirate dev".
x-html
x-html sets the "innerHTML" property of an element to the result of a given expression.
WARNING
Use this only on trusted content and never on user-provided content. Dynamically rendering HTML from third parties can easily lead to XSS vulnerabilities.
Here's a basic example of using x-html to display a user's username:
html
<div x-data="{ username: '<strong>pirate dev</strong>' }">
Username: <span x-html="username"></span>
</div>Now the
<span>tag's inner HTML will be set to<strong>pirate dev</strong>.
