Hello, here is my project link: https://codepen.io/dimitris51/pen/bMPjqd
After the visitor types something in the input form he gets the title, description and the link, as you can see in the JS console, and after that, I am saving those data in some variables which are meant to be displayed on the page, under the div with the class second
I save the title in the variable newDivForTitle
and the description in the newDivForDescription
variable which both use the createElement method to create their own divās. I am trying to place to newDivForDescription
div in the newDivForTitle
div without success so far.
Here is my JS code, everything is in a for loop
$.getJSON(url, function(data) {
for (var i=0; i<data[1].length; i++) {
title = `${data[1][i]}`
description = `${data[2][i]}`
link = `${data[3][i]}`
console.log(title, description, link);
var newDivForTitle = document.createElement("div");
var newDivForDescription = document.createElement("div");
newDivForTitle.className = i+" parentDiv";
newDivForTitle.setAttribute("id",i)
newDivForDescription.className = "description";
document.getElementById("second").appendChild(newDivForTitle);
document.getElementById(i).appendChild(newDivForDescription);
$(newDivForTitle).html(title+'<br>');
$(newDivForDescription).html(description);
}
});