Content API
Overview
In addition to accessing or modifying the content of selected DOM elements, the "data-it" attribute can be used to assign a variable, allowing its value to be accessed or changed directly through the "it" object.
Example of HTML markup with variable assignment:
<div data-it="bookName">Cat</div>
<div data-it="user.name">Alex</div>
<div data-it="userContent">
<div data-it="user.id">10</div>
<div data-it="user.name">Alex</div>
<div data-it="user.email">alex@example.com</div>
</div>
Example of getting variable values:
const bookName = it.bookName;
const userContent = it.userContent;
const userId = it['user.id'];
const userName = it['user.name'];
const userEmail = it['user.email'];
A number of type number will be returned instead of a string if the string contains only digits, a period, and a negative sign.
If no DOM element with the given variable is found on the page, attempting to retrieve the value will return null.
If no DOM element with the given variable is found on the page, attempting to retrieve the value will return null.
Example of setting variable values:
it.bookName = 'Cat 2';
it.userContent = '<div>...</div>';
it['user.id'] = 20;
it['user.name'] = 'Taylor';
it['user.email'] = 'taylor@example.com';