Get References from HTML Built with Template Literals

One thing JavaScript template literals are great at is little blocks of HTML. Like:
// Probably from some API or whatever
const data = {
title: “Title",
content: "Content"
};
const some_html = `

<h2>${data.title}</h2>
<p>${data.content}</p>
</div>
`;
But that’s still just a string. It’s not ready to append to the DOM just yet. And what if we need references to those elements inside somehow?

We’ve written about a couple of libraries that are in this vein: lit-html…
The post Get References from HTML Built with Template Literals appeared first on CSS-Tricks.

Link: https://css-tricks.com/get-references-from-html-built-with-template-literals/