0

so i have two files index.php and footer.php. and i want to add a jquery script to my index.php. so i did this and it works fine:
index.php

<html>
<body>
    <script type = "text/javascript" src = "JQUERY/jquery.js"></script>

<?php
include("include/footer.php");
?>

footer.php

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

</body>
</html>

problem is that why do i need to add same script two times? should i just add jquery script only in footer.php. and since iam adding include in index.php. it should add the script too. for ex:
index.php

<html>
<body>

<?php
    include("include/footer.php");
?>

footer.php

        hellowworld 
        <script type = "text/javascript" src = "JQUERY/jquery.js"></script>

</body>
</html>

but this doesnt work and i cant seem to find out why?
note inlude tag is working right. it does print helloworld in index.php

4
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by jstfsklh211
0

How do you know it's not working? What other jQuery are you running that isn't working?
Any jQuery code you run needs the jQuery library to already be included before the code can function. Therefore you have 2 options:
Place the code after your <script src...> tag
Or make the code execute once the rest of the document is finished loading (recommended):

$(document).ready(function() {
    // Your jQuery code here
});

On a side note, a shorthand way to write the code above is:

$(function() {
    // Your jQuery code here
});
0

yes my jquery code is in $(document).ready(function(){});

but still doesnt work.

0

Any reason why you aren't adding the jQuery script reference in your index page, put within the head element, after your style element?

0

to repeat and clarify a little

<html><head>
<!--
put all your js/css includes here

then put your $(document).ready(function(){}); here
-->
</head><body>
<!--
content goes here
-->
</body></html>

i dont claim its the best way to do it but this check this post
Simple PHP templates

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.