Hi Martin,
Welcome to TSDN...
I experienced this problem not too long ago. The issue is that you are trying to change the innerHTML of an XML document, I assume that you are using XHTML not HTML.
IE does not allow the innerHTML of a valid document to be changed as if the changed content is not valid XML then the document structure could become corrupted. To add/delete content you would need to create an element and then add it to the document using the appendChild method, for example:
-
<body>
-
<div id="container">
-
<img id="image1" src="someimage.jpg" alt="Pretty picture" />
-
</div>
-
</body>
-
To remove the image:
-
var $img = document.getElementById('image1');
-
var $container;
-
$container = document.getElementById('container');
-
$container.removeChild($img);
-
To add some text in a paragraph tag:
-
var $para = document.createElement('p');
-
var $container;
-
$container = document.getElementById('container');
-
-
$para.innerHTML="Lorem Ipsum";
-
// Give the element an id to make it easy to select and remove later.
-
$para.id="p1";
-
$container.appendChild($para);
-
This will add the paragraph element at the end of the div. You can use the insertBefore to specify the position of the node.
Another method that may be of use would be the replaceChild method, using the initial XHTML snippet this would replace the image with the paragraph:
-
var $img = document.getElementById('image1');
-
var $container;
-
$container = document.getElementById('container');
-
-
var $para = document.createElement('p');
-
$para.innerHTML="Lorem Ipsum";
-
// Give the element an id to make it easy to select and remove later.
-
$para.id="p1";
-
-
$container.replaceChild($para, $img);
-