const showJoke = (id, category, joke, updated) => {
return `
<div class="joke">
<div class="joke__id">
id: <a href="https://api.chucknorris.io/jokes/${id}">ID: ${id}</a><img src="../link.png" alt="">
</div>
// на эту картинку нужно повесить событие
<img class="img" src="https://img.icons8.com/ios/50/000000/like.png">
//
<div class="joke__text">
${joke}
</div>
<div class="joke__info">
<div class="info__updated">
Last update: ${updated} hours ago
</div>
<div class="info__category">
${category}
</div>
</div>
</div>
`;
};
const $template = render(showJoke("3214asfas", "Test", "DWda", 5321532462), ($el) => {
$el.querySelector(".img").addEventListener("click", () => alert("Click"));
});
document.body.appendChild($template);
function render(html, callback) {
const root = document.implementation.createHTMLDocument();
root.body.innerHTML = html;
const $el = root.body.children[0];
callback($el);
return $el;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.