ie7 preserve whitespace on dynamically injected text
Posted
by Rajat
on Stack Overflow
See other posts from Stack Overflow
or by Rajat
Published on 2010-05-28T23:10:45Z
Indexed on
2010/05/28
23:32 UTC
Read the original article
Hit count: 327
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function init(){
document.getElementById('test2').innerHTML = '1 2';
}
</script>
<style type="text/css">
#test{
white-space:pre;
}
#test2{
white-space:pre;
}
</style>
<title></title>
</head>
<body onload="init();">
<div id="test">
1 2
</div>
<div id="test2"></div>
</body>
</html>
Here is an example page showing my problem. I have two divs. Each has this text '1 2' with white-space. The only difference is that one is injected dynamically and one is in the html itself.
If you open the above page in IE7, the text in div test2 doesn't respect white space. How can i get the same behavior for the text that is dynamically injected??
P.S. My doctype is triggering standards mode on IE7.
© Stack Overflow or respective owner