skip to Main Content

How can I write a JavaScript variable inside double quotation marks in a template literal?

I have this code: const newDiv = document.createElement('div'); newDiv.innerHTML = ` <button class='btn btn-download'> <span class='icon'>⇩</span> Download Subtitle </button> <span>as</span> <select id=`outputFormatSelectId`> <option value="text">Text</option> <option value="text-with-time">Text with Time</option> <option value="json">JSON</option> <option value="srt">SRT</option> </select>`; Notice <select id="outputFormatSelectId"> has a id outputFormatSelectId.…

VIEW QUESTION

Javascript – What is the function of the hash tag in this template literal?

This is the code I don't understand: // Show the selected panel grandparent.parentNode .querySelector(`#${target.getAttribute("aria-controls")}`) .removeAttribute("hidden"); specifically: .querySelector(`#${target.getAttribute("aria-controls")}`) It's copied from an MDN page about accessible tabs. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tab_role. How does the template literal work? To be more precise, what is that…

VIEW QUESTION
Back To Top
Search