views:

50

answers:

1

Is there an alternative to innerHTML? - issue on Blackberry browser

Blackberry 4.6 browser does not seem to use innerHTML properly. Instead of replacing contents, it appends contents!

function load_activities(){
    x$('#dummy').xhr('program.php',{
    method:'post', 
    data:   'action=list'.              
    callback: function(){
            document.getElementById("status2").innerHTML = this.responseText;
        }       
    });
+1  A: 

How about cloning the node without children and then adding the new content?

callback: function () {
    var status2 = document.getElementById("status2");
    var copy = status2.cloneNode(false); // false indicates to not copy children
    copy.innerHTML = this.responseText;
    if (status2.nextSibling) {  // put the copy in the same place as the existing node
        var refchild = status2.nextSibling;
        status2.parentNode.removeChild(status2);
        refchild.parentNode.insertBefore(copy, refchild);
    }
    else { // existing node is the last child, copy can be appended to the end of the list
        var parent = status2.parentNode;
        parent.removeChild(status2);
        parent.appendChild(copy);
    }
}    

I have no way to test this, so I don't know for sure that cloneNode will work as expected and only copy the tags and attributes. Hope it helps.

lincolnk
absolutely brilliant. Popped it in and it worked first shot!
robert