-
-
Save bantic/a777fcfe95579d4c320a4dd964a5c63d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function injectJquery(callback) { | |
if (window.jQuery) { | |
return callback(window.jQuery); | |
} | |
let script = document.createElement('script'); | |
script.setAttribute( | |
'src', | |
'//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js' | |
); | |
script.onload = () => callback(window.jQuery); | |
script.onerror = e => alert('The script failed to load: ' + e); | |
document.head.appendChild(script); | |
} | |
injectJquery(function($) { | |
$('img').attr('src', '//www.fillmurray.com/200/300'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment