[jQuery] $(document.createElement("script")) vs. $("<script>") ?!
During my todays hacking on the jquery.xsajax.js plugin (see different
mail) I had to discover that there is a strange difference between
var node =
$(document.createElement('script')) <====
.attr('type', 'text/javascript')
.attr('src', url);
$("head", document).append(node);
and
var node =
$("<style>") <====
.attr('type', 'text/javascript')
.attr('src', url);
$("head", document).append(node);
In FF both produced a <script> node which fires just fine and loads the
code form the URL. But in MSIE6 and MSIE7 the <script> node is just
silently ignored. Nothing happens, not even an error. Hence I sticked
with the $(document.createElement('script')) approach which worked just
fine also in MSIE.
The question for me now is: what did I misunderstood here? Can
someone shed some light on me where the difference in the resulting
jQuery nodes is? At least I was under the impression that both
$(document.createElement('script')) and $("<style>") give me the same
type of resulting <script> node wrapped into a jQuery object...
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com