views:

34

answers:

1

Once I create a range how do I display the HTML content of it in Firefox? range.toString() only gives me the text content. In essence, like innerHTML returns the markup in IE. Thanks

function innerHTML(oTarget, sContent, bAppend){
if (document.getElementById && !document.all) {//is this a non ie browser
    var range = document.createRange();
    range.setStart(oTarget, 0);
    range.setEnd(oTarget, oTarget.childNodes.length);
    if (sContent) {//if there is content, save it if not return the content
        var htmlFrag = range.createContextualFragment(sContent);
        if (bAppend != true) {//append or replace
            range.deleteContents();
        }
        oTarget.appendChild(htmlFrag); //add the new html
    } else {
        sContent = range.toString();
    }
} else {
    if (sContent) {
        if (bAppend == true) {
            oTarget.innerHTML += sContent;
        } else {
            oTarget.innerHTML = sContent;
        }
    }
    sContent = oTarget.innerHTML;
}
return sContent;
}
A: 

innerHTML is part of the JavaScript standard and is supported by all modern browsers. Your else statement (for IE) should work in Firefox as well, as long as oTarget is an HTML element object.

KevnRoberts
I need the flexibility for oTarget to be anything really. innerHTML runs into snags on non-IE in some cases. I am hoping someone knows the answer to the range HTML display question.
Praesagus