NickName:Anurag Ask DateTime:2015-02-03T06:07:32 Javascript in javascript IF condtion How can I call another javascript in a condition. Lets say I have <script type="text/javascript"> if(condition) { < script type="text/javascript" src="">< /script>} else(condition) { < script type="text/javascript" src="">< /script>} Copyright Notice:Content Author:「Anurag」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.Link to original article:https://stackoverflow.com/questions/28287703/javascript-in-javascript-if-condtion Answers user4058999 2015-02-02T22:14:00 How about:\n\n <script type=\"text/javascript\">\n var head = document.getElementsByTagName(\"head\")[0];\n var script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n if(condition) {\n script.src = \"one.js\";\n } else {\n script.src = \"two.js\";\n } \n head.appendChild(script);\n </script>\n", w3bMak3r 2015-02-02T22:14:32 How about place something like this in your head:\n\n<script>\n if(someCondition){\n document.write(\\'<script src=\"awesome-script-a.js\"><\\/script>\\');\n }\n else{\n document.write(\\'<script src=\"awesome-script-b.js\"><\\/script>\\');\n }\n\n\n</script>\n\n\nThis is how HTML5 Broiler plate and The Roots.io Starter theme handles scripts loaded via CDN.\n\nThere is a slight performance hit as document.write writes to an already open page. \n\nSee http://javascript.info/tutorial/document-write", Rinrub 2015-02-02T22:10:26 getscript method in jquery lest you Get a script inside your JavaScript code", camilaazuma 2017-10-05T21:47:02 Try something like:\n\n<script type=\"text/javascript\">\n var script = document.createElement('script');\n script.type = 'text/javascript';\n script.src = true ? 'source1' : 'source2';\n document.querySelector('head').appendChild(script);\n</script>\n",