开发者

can't add scripts to head with jquery

I'm trying开发者_StackOverflow社区 to add a script (like below) to the head but it's not working. Any ideas on how I'm messing this up?

$("<script src='http://mysite.com/slides.min.jquery.js'></script>").appendTo("head");


you can use jQuery.getScript()

$.getScript('ajax/test.js', function() {
     alert('Load was performed.');
});


For $ to work you need to have jquery loaded. So if it's not loaded yet, this won't work.


Try something like that :

var head = $("head")
$("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js' </script>").appendTo(head);

I won't ask you why you would like to import JQuery library since you already have JQuery in your page (you wouldn't use $ if that wasn't the case, don't you ;-) )


You don't have to append this to head. You can append it to body, it will work, no reason to worry about where it is appended to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜