document.createelement innerhtml INTERNET EXPLORER BAH!

Discussion in 'JavaScript' started by DavidMcK, Oct 21, 2009.

  1. #1
    So, the following code works A-OK in Firefox:
    <script language="Javascript" type="text/javascript">
       function zeroPad(num,count)
       {
           var numZeropad = num + '';
           while(numZeropad.length < count) {
               numZeropad = "0" + numZeropad;
           }
       return numZeropad;
       }
    
       today = new Date();
       var headID = document.getElementsByTagName("head")[0];
       var css = document.createElement("style");
       css.type = "text/css";
       css.innerHTML = ".month td#d" + today.getFullYear() + zeroPad(today.getMonth()+1,2) + zeroPad(today.getDate(),2)+" { border: 2px solid red; color: red; }";
       headID.appendChild(css);
    </script>
    Code (markup):
    It's supposed to generate a CSS tag with an ID based on today's date. Works fine! Internet Explorer, though :( Unknown Runtime Error at
    css.innerHTML =
    Code (markup):
    Any thoughts welcome!

    David
     
    DavidMcK, Oct 21, 2009 IP
  2. DavidMcK

    DavidMcK Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Solved my own problem. Thought I should post it here in case anyone else stumbles on this thread googling:

    http://www.phpied.com/dynamic-script-and-style-elements-in-ie/

    David:)
     
    DavidMcK, Oct 21, 2009 IP