Passing Nodes to template literal & rendering it?

I have a function returning a template literal: function generateStuff(nodes) { const output = `<ul>${nodes}</ul>`; return document.body.innerHTML = output; } nodes is an array of <li> elements made with createElement and then added to nodes via appendChild. Is there a way of render a list with generateStuff(nodes)? Right now all it returns is <ul>[object NodeList]</ul>… Read More Passing Nodes to template literal & rendering it?

Pulling out a random object of an array in a NodeList

I have this script written const termList = document.querySelectorAll(‘.term’); const randomNum = Math.random()*(termList.length-0)+0; const randomTerm = termList[randomNum]; I want to have randomTerm pull out a random <div> out from that array that has that class. As written however randomTerm when run in the console simply produces undefined. Do I need to have the NodeList array… Read More Pulling out a random object of an array in a NodeList

Creating HTML/Javascript Modal with dynamic text

I am learning Javascript and my project contains 3 buttons that open a modal. Everything works fine, however I want to reuse the modal and replace the modal text depending on which button is clicked. My HTML is below: <body> <button class="show-modal" id="btn-1">Show modal 1</button> <button class="show-modal" id="btn-2">Show modal 2</button> <button class="show-modal" id="btn-3">Show modal 3</button>… Read More Creating HTML/Javascript Modal with dynamic text