If a site you're editing using one version of jQuery, and upgrading breaks a lot, and a new script you're working on needs a newer version, is there a way to call and use the newer jQuery within that script such that it doesn't affect the rest of the site?
Asked
Active
Viewed 49 times
0
-
Will your script get included onto other pages with the old jQuery? – Tuan May 09 '13 at 22:37
1 Answers
0
Take a look at http://api.jquery.com/jQuery.noConflict/. They even have an example of using two different versions of jQuery. This isn't recommended though.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="log">
<h3>Before $.noConflict(true)</h3>
</div>
<script src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script>
var $log = $( "#log" );
$log.append( "2nd loaded jQuery version ($): " + $.fn.jquery + "<br>" );
/*
Restore globally scoped jQuery variables to the first version loaded
(the newer version)
*/
jq162 = jQuery.noConflict(true);
$log.append( "<h3>After $.noConflict(true)</h3>" );
$log.append( "1st loaded jQuery version ($): " + $.fn.jquery + "<br>" );
$log.append( "2nd loaded jQuery version (jq162): " + jq162.fn.jquery + "<br>" );
</script>
</body>
</html>

Dan P.
- 1,433
- 1
- 16
- 28