naval
naval

Reputation: 1413

Javascript function not working cross-browser.

This is my javascript function that is working in chrome and FF5 but not working in IE.

function createContorl() {
    var parentDiv = document.createElement("div");

    parentDiv.setAttribute("class", "ModelProgressDiv");
    parentDiv.setAttribute("Id", "ProgressDiv");

    var innerContent = document.createElement("div");

    innerContent.setAttribute("class", "ModalProgressDivContent");

    var img = document.createElement("img");

    img.setAttribute("src", "images/loading_large.gif");
    parentDiv.appendChild(innerContent);

    innerContent.appendChild(img);
    document.body.appendChild(parentDiv);
}

Upvotes: 0

Views: 270

Answers (2)

Quentin
Quentin

Reputation: 944568

setAttribute is broken in IE unless you are using a very recent version in Standards Mode. It sets properties instead of attributes so it fails when the property doesn't have the same name as the attribute. Don't use it.

parentDiv.className = "ModelProgressDiv"; // etc

Upvotes: 2

VinayC
VinayC

Reputation: 49245

Your code works fine on IE8: see this fiddle

BTW, please check the in the function name createContorl but that would cause problem in all browsers.

Perhaps, you should explain when you say "not working in IE".

Upvotes: 0

Related Questions