Question: I wrote the following code to loop through an object and display it in the browser:

```
function showSearchResults(resultsObj) {
    var results = resultsObj.hits
    for (var i=0;i<results.length;i++) {
        resultsDiv.innerHTML += '<div class=\'ultimate-search-result\'>' + results[i].description;
        if (results[i].linktoken) {
            resultsDiv.innerHTML += '<a href=\'' + results[i].linktoken + '\'><i class=\'icon-pencil\'></li></a>';
        }
        if (results[i].linkpart) {
            resultsDiv.innerHTML += '<a href=\'' + results[i].linkpart + '\'><i class=\'icon-info-sign\'></li></a>';
        }
        resultsDiv.innerHTML += '</div>';
    }   
}

```

When I run the code in the browser the link icons appear underneath the description, when I inspect the code in Chrome the div is closed at the end of the result description line instead of after the link icons while in the code the is supposed to be inserted after the links. In Firefox I experienced the same problem. 

Error can be seen in the following fiddle <http://jsfiddle.net/v6DjA/>

Answer: 
Alright so the browser did not like how you were adding to the div. So break it up into a variable then append to that then add that to the innerHTML at the end. See example below.

```
var html = "";
for (var i = 0; i < results.length; i++) {
    html += '<div class=\'ultimate-search-result\'>' + results[i].description;
    if (results[i].linktoken) {
        html += '<a href=\'' + results[i].linktoken + '\'>link 1</a>';
    }
    if (results[i].linkpart) {
        html += '<a href=\'' + results[i].linkpart + '\'>link 2</a>';
    }
    html += '</div>';
}
resultsDiv.innerHTML = html;

```

Here is a link to [fiddle](http://jsfiddle.net/johnstew/cFYX4/).
The browser is closing the div for you on the first line.

```
    resultsDiv.innerHTML += '<div class=\'ultimate-search-result\'>' + results[i].description;

```

So you see the div ending after this.

```
htmlData = "";
for (var i=0;i<results.length;i++) {
    htmlData += '<div class=\'ultimate-search-result\'>' + results[i].description;
    if (results[i].linktoken) {
        htmlData  += '<a href=\'' + results[i].linktoken + '\'><i class=\'icon-pencil\'></li></a>';
    }
    if (results[i].linkpart) {
        htmlData  += '<a href=\'' + results[i].linkpart + '\'><i class=\'icon-info-sign\'></li></a>';
    }
    htmlData  += '</div>';
}   
resultsDiv.innerHTML=htmlData;

```

<http://jsfiddle.net/v6DjA/5/>