In my project, I am working with an XMLHTTPResponse object that contains nodes. My goal is to print the elements of one specific node (serps) in a div element, but in a formatted manner. The structure of the node is as follows:
Currently, I need to create a div element to store serps information such as response.serps1.headline+"
"+response.serps1.url+"
"+response.serps2.headline+"
"+response.serps2.url etc. In my code attempts have looked like this:
//Data
var divSerp3 = createElement('div', 'divSerp3', 'divSerp3css');
if (typeof(response.serps) === 'undefined' || response.serps === null) {
tse3 = document.createTextNode("NO DATA");
} else {
tse3 = document.createTextNode(response.serps[1].headline+" <br>"+response.serps[1].url+"<br><br>"+response.serps[2].headline+" <br>"+response.serps[2].url+"<br><br>"+response.serps[3].headline+"<br>"+response.serps[3].url+"<br><br>"+response.serps[4].headline+"<br>"+response.serps[4].url+"<br><br>"+response.serps[5].headline+" <br>"+response.serps[5].url);
}
divSerp3.appendChild(tse3);
However, the output does not meet the desired formatting. How can I iterate through the entire serps node and insert data into my div element in a properly formatted way?