I want to add a element into the existing DOM to have the javascript code run.
I did this with YUI:
var scriptNode = Y.Node.create('<script type="text/javascript" charset="utf-8">alert("Hello world!");<\/script>');
var headNode = Y.one('head');
headNode.append(scriptNode);
It's successfully added to the DOM but it doesn't give me an alert.
Someone knows what the problem is?
scriptNode
under your control? Wrap it in a function and call it after appending it? Just found this - seems appropriate and informative: stackoverflow.com/questions/610995/…</
in the string isn't mistaken for the closing tag of the enclosing script element. It is consdered good practice for closing tags in string literals.