Thompson Thompson - 9 months ago 47
Javascript Question

Include jQuery, if not included already

I want to include the jquery in file, if not included already in the page.
How can I do this?

I wrote this, but it's giving undesired output.

<script type="text/javascript">
if ('undefined' == typeof window.jQuery) {
// jQuery not present
// alert("Jquery Unavailable");
<?php echo '<script type="text/javascript" src=""></script>'; ?>
} else {
// jQuery present
alert("Jquery Available");


you cant do that in PHP. Try this instead

<script type="text/javascript">

if(typeof jQuery == 'undefined'){
        document.write('<script type="text/javascript" src=""></'+'script>');