I want to create a script tag by jQuery.
I use the following code:
$("<body>").append("<script></script>");
It doesn't work. What will you do to acheive it?
I want to create a script tag by jQuery.
I use the following code:
$("<body>").append("<script></script>");
It doesn't work. What will you do to acheive it?
You should do it like so
var script=document.createElement('script');
script.type='text/javascript';
script.src=url;
$("body").append(script);
The error is in the selector:
$("body").append("<script>alert('hello world');<\/script>");
Note that you have to escape the unallowed characters in the appended string.