Share via


CreateElement no longer supports angle brackets

As of Windows Internet Explorer 9, the createElement triggers an "object not found" exception when you use angle brackets (< >).

The following example shows the code that's affected by this change:

var elm = document.createElement("<div id='myDiv'>");

Starting with IE9 standards mode, this code triggers an "object not found" exception. (In earlier document modes, the element is created and the attribute values are assigned.)

To fix this, update your code to call createElement without angle brackets.

To assign attribute values, (such as id, name, etc.), call setAttribute after creating the element:

var elm = document.createElement("div");
elm.setAttribute("id","myDiv");

Alternatively, you can use innerHTML to assign HTML markup to the new element:

var parent=document.createElement("div");
parent.innerHTML="<div id='myDiv'></div>";
var elm=parent.firstChild;

Note: You can also use a legacy document mode, however, this should be considered a temporary measure.

createElement

Discovering Internet Explorer Developer Tools

Specifying Document Compatibility Modes