Has anyone experienced the following strange behavior in Internet Explorer? Does anyone know how to get around this?
Save the following code and open in IE, and select the whole line of the word "Red" (select from left to right) and then click the button. The word "Blue" turns red. If you select the paragraph of "New", the word "Blue" turns black. I've seen this happen with the "class" attribute as well as "style".
Note: I'm using Internet Explorer 7.
Save the following code and open in IE, and select the whole line of the word "Red" (select from left to right) and then click the button. The word "Blue" turns red. If you select the paragraph of "New", the word "Blue" turns black. I've seen this happen with the "class" attribute as well as "style".
Code:
<html>
<body>
<input type="button" value="Click Me" onclick="javascript:document.selection.createRange().pasteHTML('<p>New</p>');alert(this.parentNode.outerHTML);" />
<div>
<p style="color:red;">Red</p>
<p style="color:blue;">Blue</p>
</div>
</body>
</html>
Note: I'm using Internet Explorer 7.