I've got a script that I'm trying to modify so that I don't load the jQuery library if its already present. However, the only way I can get things to work is example 1 below (explictly loading the jQuery library). When I try to conditionally load it, the slider does not work...
Example #1 - the slider works fine in this example (but jQuery may be loaded multiple times)
<head>
<script type='text/javascript' src='scripts/js/jquery-1.4.2.min.js'></script>
<script type='text/javascript' src='scripts/js/slider/jquery.slider.js'></script>
<script type='text/javascript'>
jQuery(document).ready(
function(){
jQuery('#accordion-1').slider({
autoStart:true,
slideInterval:5000,
slideNum:false
});
})
</script>
</head>
Example #2 - Trying to dynamically load jQuery. Slider does not work.
<head>
<script type='text/javascript'>
if (typeof jQuery == 'undefined') {
// jQuery is not loaded => load it:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
document.getElementsByTagName('body')[0].appendChild(script);
}
</script>
<script type='text/javascript' src='scripts/js/slider/jquery.slider.js'></script>
<script type='text/javascript'>
jQuery(document).ready(
function(){
jQuery('#accordion-1').slider({
autoStart:true,
slideInterval:5000,
slideNum:false
});
})
</script>
</head>
Example #3 - This does not work either...
<head>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape('%3Cscript src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"%3E%3C/script%3E'));
}
</script>
<script type='text/javascript' src='scripts/js/slider/jquery.slider.js'></script>
</head>