From 9edd9627054b78f64cabd005cffca5a0808281c9 Mon Sep 17 00:00:00 2001 From: Maksym Kobieliev Date: Thu, 7 Mar 2024 18:37:30 +0200 Subject: [PATCH] fix(simple-service-worker): avoid HTML to appear as text (#234) * Fix #191 Fixes https://github.com/mdn/dom-examples/issues/191 * Update service-worker/simple-service-worker/app.js Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com> --------- Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com> Co-authored-by: Brian Thomas Smith --- service-worker/simple-service-worker/app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/service-worker/simple-service-worker/app.js b/service-worker/simple-service-worker/app.js index 72472bf5..e5f4f308 100644 --- a/service-worker/simple-service-worker/app.js +++ b/service-worker/simple-service-worker/app.js @@ -42,7 +42,11 @@ const createGalleryFigure = async (galleryImage) => { const myImage = document.createElement('img'); const myCaption = document.createElement('caption'); const myFigure = document.createElement('figure'); - myCaption.textContent = `${galleryImage.name}: Taken by ${galleryImage.credit}`; + const myName = document.createElement('span'); + myName.textContent = `${galleryImage.name}: `; + const myCredit = document.createElement('span'); + myCredit.innerHTML = `Taken by ${galleryImage.credit}`; + myCaption.append(myName, myCredit); myImage.src = window.URL.createObjectURL(imageBlob); myImage.setAttribute('alt', galleryImage.alt); myFigure.append(myImage, myCaption);