Append a JavaScript code to DOM and run it

When you have a user input box to promote to the frontend with plain JavaScript, attached via JSON-P or other approach serving JSON, there are few hints for appending. For instance, we have a script tag that has to generate a dynamic content. We need to locate it somehow, two possible approaches are: 1) pulling the last loaded script, usually the one executed right at the moment: [javascript] var scripts = document.getElementsByTagName( 'script' ); var script_element = scripts[ scripts.length - 1 ]; [/javascript] 2) getting the script via ID [javascript] var script_element = document.getElementById( script_id ); [/javascript] In order to append… Continue Reading