Last active
March 17, 2018 09:21
-
-
Save afjlambert/bb51440c1871ac409dae to your computer and use it in GitHub Desktop.
multiple jquery's
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
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js"></script> | |
<script> | |
_$ = jQuery.noConflict(); // make our own safe version | |
$ = jQuery; // support cms widgets and other third parties | |
(function(version){ | |
// Developers: don't do this! It's not safe. | |
$(function(){ | |
console.log(version, $.fn.jquery, 'dom loaded unsafe 1'); | |
}); | |
// Don't doo this eighter | |
jQuery(function(){ | |
console.log(version, jQuery.fn.jquery, 'dom loaded unsafe 2'); | |
}); | |
// Do this instead | |
_$(function(){ | |
console.log(version, _$.fn.jquery, 'dom loaded safe'); | |
}); | |
}($.fn.jquery)) | |
</script> | |
</head> | |
<body> | |
<h2>CMS widgets</h2> | |
<script> | |
(function(version){ | |
$(function(){ | |
console.log(version, $.fn.jquery, 'dom loaded for cms widgets'); | |
}); | |
}($.fn.jquery)) | |
</script> | |
<h2>Some external party</h2> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"></script> | |
<script> | |
(function(version){ | |
$(function(){ | |
console.log(version, $.fn.jquery, 'dom loaded for external party') | |
}); | |
}($.fn.jquery)) | |
</script> | |
<script> | |
_$(function(){ | |
console.log(_$.fn.jquery, 'another safe one'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment