I'm new to JavaScript and I really like jQuery and hate when it comes to writing some cumbersome code to do simple things.
I'm currently trying to load external JS dynamically and execute it (to communicate with the Google Translate API).
The sample code creates a tag script, sets it, srcand adds it to the document headto execute it:
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
var sourceText = escape(document.getElementById("sourceText").innerHTML);
var source = 'https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&callback=translateText&q=' + sourceText;
newScript.src = source;
document.getElementsByTagName('head')[0].appendChild(newScript);
I wonder if there is one liner in jQuery for this.
source
share