innerHTML removes attribute quotes in Internet Explorer

Posted by Augustus on Stack Overflow See other posts from Stack Overflow or by Augustus
Published on 2009-08-05T07:59:43Z Indexed on 2010/06/03 5:34 UTC
Read the original article Hit count: 436

When you get the innerHTML of a DOM node in IE, if there are no spaces in an attribute value, IE will remove the quotes around it, as demonstrated below:

<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="div1"><div id="div2"></div></div>
        <script type="text/javascript">
            alert(document.getElementById("div1").innerHTML);
        </script>
    </body>
</html>

In IE, the alert will read:

<DIV id=div2></DIV>

This is a problem, because I am passing this on to a processor that requires valid XHTML, and all attribute values must be quoted. Does anyone know of an easy way to work around this behavior in IE?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about internet-explorer