DEV Community

Discussion on: Binding CSS and JavaScript with HTML data-attributes

Collapse
taufik_nurrohman profile image
Taufik Nurrohman

Or to store application states:

<textarea data-config='{"foo":"bar"}'></textarea>
Enter fullscreen mode Exit fullscreen mode
document.querySelectorAll('textarea[data-config]').forEach(elem => {
    let config = JSON.parse(elem.dataset.config || '{}');
    let app = new App(elem, config);
});
Enter fullscreen mode Exit fullscreen mode