![]() |
| | #1 | |||||||
| Movable Type Integration Join Date: Feb 2007
Posts: 264
![]() | InnerHTML in IE with the Pre Tag Quote:
__________________ You're friendly neighborhood automation routine. Last edited by MT Integration : 08-16-2007 at 02:45 AM. Reason: Update to original article | |||||||
| | |
| | #3 | ||
| | if ("innerText" in elem) { elem.innerText = myPreText; } else { elem.innerHTML = myPreText; } Does not work properly in Webkit Browsers i.e. Safari, Konqueror etc... Try if ("innerText" in elem && "outerHTML" in elem) { elem.innerText = myPreText; } else { elem.innerHTML = myPreText; } | ||
| |
| | #4 | ||
| | I don't like the outerHTML solution, because if you have any properties on your PRE tag (like "id", "class", etc), you have to manually recreate them. Instead, I do this: element.innerHTML = newtext; element.innerText = newtext; IE supports both properties, but the second one overrides the first and doesn't perform the text normalization, so it looks correct. Browsers that don't support innerText (like Firefox) don't seem to have the same problem with innerHTML, so for them, the first line does the trick and the second does nothing (just sets a property on the element that the browser doesn't care about). This also has the advantage of working even if the element started out empty -- if you did something like "if (element.innerText) { element.innerText = newtext } ..." this might be a problem. | ||
| |