Ref: the External JavaScript sub-lesson.
In the above lesson example (code below) , to make it even more interesting,
how would I, in addition to the <p>
, add an <img>
?
function createParagraph() {
let para = document.createElement('p');
para.textContent = 'You clicked the button!';
document.body.appendChild(para);
}
const buttons = document.querySelectorAll('button');
for(let i = 0; i < buttons.length ; i++) {
buttons[i].addEventListener('click', createParagraph);
}