The JS code below adds an extra paragraph to the HTML page on click of a button. But how can I change this code to add an image | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The JS code below adds an extra paragraph to the HTML page on click of a button. But how can I change this code to add an image

function newParagraph() { var element = document.createElement("p"); var main = document.getElementById("main"); main.appendChild(element); var text = document.createTextNode("The Battle of Salamis was fought between an alliance of Greek cities and the Persian Empire in 480 BC. The Greeks decisively defeated the Persian navy."); element.appendChild(text); }

17th Jun 2018, 9:18 PM
Masquerade
Masquerade - avatar
3 Answers
+ 1
ok. Will I still have to create new element ? as in : var element = document.createElement("IMG"); ?
17th Jun 2018, 9:27 PM
Masquerade
Masquerade - avatar
0
Peter Claver uhh why did you delete your answer ?
17th Jun 2018, 9:49 PM
Masquerade
Masquerade - avatar
0
Masquerade I'm getting you the exact thing
17th Jun 2018, 9:50 PM
Peter Claver
Peter Claver - avatar