problem with document.body.appendChild() on IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skavinkar
    New Member
    • Jun 2012
    • 23

    problem with document.body.appendChild() on IE

    I am trying to display loading prompt by creating elements using javascript
    Code:
    var text = document.createElement('div');
                                    text.innerHTML = '<br/><center>Loading........Please Wait!</center>';
                                    text.style.height = "80px";
                                    text.style.width = "350px";
                                    text.style.background = "#000";
                                    text.style.opacity = 0.7;
                                    text.style.color = '#fff';
                                    var header = document.createElement('span');
                                    header.innerHTML = "";
                                    header.style.height = "50px";
                                    header.style.width = "350px";
                                    header.appendChild(text);
                                    header.style.position = "absolute";
                                    header.id = "Loadingmsg1";
                                    $(header).css('top', '250px');
                                    $(header).css('left', '300px');
                                    document.body.appendChild(header);
    When i debug this code on chrome once the last line is excuted it shows up the message but not on IE(tested on ver 9)
    where i am getting wrong? Please help
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    In, IE, elements are not available for use until it has loaded. You need to put your code in a function and then call said function in the onload event of the body.

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      I actually don't see a problem with your code I tested in firefox and ie the only difference i made to your code was that i got rid of the jquery and directly set the style properties?

      Comment

      Working...