43
To load from a url:
$("body").append($("<script />", {
src: url
}))
To load from existing source code:
$("body").append($("<script />", {
html: code
}))
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.