1

I am using this script to dynamically add scripts that loads graph in my page. This code works fine in chrome, Safari and FF but not in IE(!!)..

$.post("shorts.server.php", $.param({

    S_number: stocknumber,

}), function(response) {

    script = document.createElement('script');
    //dynamic_graph.js changes it's content by the current selected stock
    script.src = 'jQuery/head/dynamic_graph.js';
    $("#graphMain" + id).append(script);

    var head = document.getElementsByTagName('body')[0];
    script = document.createElement('script');

    script.src = 'jQuery/head/dynamic_info.js';

    head.appendChild(script);
});​
  1. you can see that I tried both techniques to append the scripts dynamically.
  2. they both don't work in IE. can you suggest a better way to append the scripts? 1 more less important but related question:
    1. what is the currect way to post a script in stackoverflow??, because sometimes it's colored and sometimes it's grayed...
Jivings
  • 22,834
  • 6
  • 60
  • 101
devmonster
  • 1,729
  • 8
  • 24
  • 48

1 Answers1

0

When I was trying to append dynamic elements to the DOM in IE a while ago, I found that I needed to do it the other way round to get it to work. So instead of

$("#graphMain" + id).append(script);

try

$(script).appendTo($("#graphMain" + id));
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
  • hi clark, thank for the reply. I tried it and it errored me with "script.appendTo is not a function" – devmonster May 24 '12 at 09:42
  • thanks. but that doesn't work either. I have read many posts here (like [link]http://stackoverflow.com/questions/7090198/using-appendchild-with-ie-in-javascript and [link]http://stackoverflow.com/questions/436710/element-appendchild-chokes-in-ie) but I need to append a script to the body tag, AND I NEED TO DO IT A FEW TIME , everytime the user presses a row – devmonster May 28 '12 at 07:09