According to http://api.jquery.com/jQuery/#jQuery-html-ownerDocument you can create DOM elements on the fly from a string of raw HTML. This works, for example, on <p></p>
.
But when I try $('<script></script>')
, the </script>
part get's interpreted as the end of actual script and you will see the rest of the code as text in your browser like this: ').appendTo('body');
and I get the following error in Chrome console Uncaught SyntaxError: Unexpected token ILLEGAL
file.html
<!DOCTYPE HTML>
<head></head>
<body>
<script src="/jquery-2.1.1.min.js"></script>
<script>
$('<p></p>').appendTo('body');
$('<script></script>').appendTo('body');
</script>
</body>
I also tried $.parseHTML('<script></script>').appendTo('body');
but it gave me the same error.
I can't find any typo. Is this a bug in jQuery?