(function () { function getLastChild(el) { return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el; } // should be our script tag var insertPosition = getLastChild(document.lastChild); $(document).ready(function () { // get widget via jsonp // target element should be create at insertPosition, i.e. $(insertPosition).after('

widget inserted here

'); }); })();