I tried to run the following code which showed up a blank screen
function make() {
for (var i = 1; i <= 8; i++) {
var j = "d" + i;
var c = document.createElement("div");
c.setAttribute("id",j);
document.getElementById(j).innerHTML = 'Hello<br>';
}
}
#d1 {font-family: 'Cinzel';}
#d2 {font-family: 'Cookie';}
#d3 {font-family: 'Great Vibes';}
#d4 {font-family: 'Monoton';}
#d5 {font-family: 'Orbitron';}
#d6 {font-family: 'Pacifico';}
#d7 {font-family: 'Righteous';}
#d8 {font-family: 'Sacramento';}
<!DOCTYPE html>
<html>
<head>
<title>Logo</title>
<link href="https://fonts.googleapis.com/css?family=Cinzel|Cookie|Great+Vibes|Monoton|Orbitron|Pacifico|Righteous|Sacramento" rel="stylesheet">
</head>
<body onload="make()">
</body>
</html>
In the above snippet, I have used a javascript function where i have created 8 elements and seperated each with a line-break . But, Unfortunately, the line containing the 'innerHTML' throws a type error and the rest of the code does not generate the desired output.
Please do help me out!
Thank You
'`? You haven't added `c` to the document yet, so `document.getElementById` can't find it. – Heretic Monkey Oct 14 '18 at 16:09
';` but you also need to insert `c` somewhere in dom – charlietfl Oct 14 '18 at 16:10