Append textNode and </BR>

Hello,
Why doesn’t the BR element get appended after every textNode in the following?

function show(){
    var d = document.getElementById('displayBox');
    var pNode = document.createElement('p');
    var bNode = document.createElement('br');

    for( var x=0; x<names.length; x++) {
        console.log("in show - names[" + x + "]:"  + names[x].fName + " " + names[x].lName);
    
        var tNode = document.createTextNode(" " + names[x].fName + " " + names[x].lName);
        pNode.appendChild(tNode);
        pNode.appendChild(bNode);
    }    
    d.appendChild(pNode);
    d.parentNode.appendChild(d);
}

Thanks very much for any help,
Gerard

Sorry, I see now that the same BR can’t be reused like that. I’d have deleted the post but I guess that can’t be done.
Gerard

Instead of appending to the p node, does it work if you append it to the t node?

Silly me, I was trying to reuse the same bNode each time when I needed to create a new Node for each iteration.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.