-1

i made a slider page for my website. after inserting the jquery scripts the code is working absolutely fine when saved as a '.html file' but when saved as a '.php file' it doesn't work. i guess there is some jquery/javascript issue.

the 'prev-slide' and 'next-slide' are linked to javascript file of the slider itself. they're working fine for a '.html file' but again not for a '.php file'

how can i call the javascript/jquery in a php file so they can be included in?

what am i missing here? please help and explain in detail as im new to this. Thanks

<div class="wrap">
<div id="slider1" class="slider">
<ul>
<a href=""><img src="img/images/logos_01.png" alt=""></a>
<a href=""><img src="img/images/logos_02.png" alt=""></a>
<a href=""><img src="img/images/logos_03.png" alt=""></a>
<a href=""><img src="img/images/logos_04.png" alt=""></a>
<a href=""><img src="img/images/logos_05.png" alt=""></a>
<a href=""><img src="img/images/logos_06.png" alt=""></a>
</ul>   
</div>
<div class="controls">

<a href="" class="prev-slide"><img src="img/images/prev.png" alt="" /></a> 
<a href="" class="next-slide"><img src="img/images/next.png" alt="" /></a> 

</div>
</div>

<style type="text/css" src="css/style.css"></style>


<script src="js/lemmon-slider.js"></script> 
<script src="js/libs/jquery.min.js" type="text/javascript"></script>


<script type="text/javascript">

$(window).load(function(){

$( '#slider1' ).lemmonSlider({

'infinite' : true

});
alert('OK');
});

</script>
5
  • 1
    What did you use to run the .php file? Commented Jan 31, 2013 at 11:59
  • 2
    You should include "jquery.min.js" first thing, before including any other .js files as those are likely using the jQuery core which is defined there. Commented Jan 31, 2013 at 11:59
  • remove the backslash in "src="js/libs/jquery.min.js\" . Commented Jan 31, 2013 at 12:00
  • @ShadowWizard as if the order suddenly matters on a PHP file Commented Jan 31, 2013 at 12:00
  • @Tim he probably had the order right in the HTML file. Commented Jan 31, 2013 at 12:01

3 Answers 3

1

Not sure if this will fix it, but try loading the jQuery source file

<script src="js/libs/jquery.min.js" type="text/javascript"></script>

before your slider script:

<script src="js/lemmon-slider.js"></script>

jQuery should always be loaded first before any other JS file, as it needs to be read before a script that uses jQuery.

Good luck :)

Sign up to request clarification or add additional context in comments.

8 Comments

THANK YOU SO MUCH ITS WORKING :) but what if we have several other kinds of scripts on the same page . Then, do i still need to place the jquery source script file above them all ??
ya you need to keep all js files that use jquery below the jquery.js file
i dnt knw why the jquery script file is not working when placed inside the actual webpage (which is footer.php) with some other scripts such as a script for facebook page likes .. is it ok to place the jquery script file at the bottom of 'footer.php' file yet above all other script files?? i.e. placing all the scripts at the bottom of the 'footer.php' file after closing of all the <divs> ??
You have to be careful with that because even though loading JS files at the bottom of a HTML file (or series of files) is better for performance, if there is a script executing at the top of the file (for example, you're using a CMS like Wordpress) then you may experience problems if that script uses jQuery, which you're loading at the bottom. To be safe I'd always load jQuery at the top. Anything else at the bottom should be fine.
im not using a CMS .. its a normal footer.php page .. the changes when made to the code i posted are working fine but not in the actual website page .. the slider is required at the footer .. do i also need to include the jquery script in any other file like is it ok to call the jquery script in the footer.php file itself or should i place them in the header.php file .. because i tried all kinds of script placements in the footer.php file still its not reading the script .. im confused dnt knw why its not working in the actual footer.php page .. Need Help Again Please –
|
0

I think this what is wrong...

The \ backslash here src="js/libs/jquery.min.js\" in the following line

<script src="js/libs/jquery.min.js\" type="text/javascript"></script>

and * in following lines

*<script type="text/javascript">

and

</script>*

1 Comment

sorry abt the backslash and the star character . was a mistake but THE PROBLEM IS STILL THERE
0

change this

 <script src="js/libs/jquery.min.js\" type="text/javascript"></script>
<style type="text/css" src="css/style.css"></style>

to

<script src="js/libs/jquery.min.js" type="text/javascript"></script>
                               --^-- //her you have extra  '\' 
<link href="css/style.css" rel="stylesheet" type="text/css" />

1 Comment

sorry abt the backslash and the star character . was a mistake but THE PROBLEM IS STILL THERE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.