0

When I put jquery code in the body of my php file it works, however when I put it in a seperate file and link it then it doesnt work? any ideas?

       <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script src="script.js"></script>
  </head>


  <body>

    <p>hello</p>

  </body>
</html>

and here is my javascript file.

$(document).ready(function(){

  $("p").click(function(){
    $("p").hide();
  });
});
Naoimi
  • 35
  • 5
  • 4
    Have you checked the browser's console for errors? And your .js and .css file links should be within the head element, not after it. The code itself however, [is fine](https://jsfiddle.net/j08691/zybfvLsd/) – j08691 Apr 05 '19 at 20:52
  • Yes, no errors in the console, I have now put them in the head section and still no luck. The code is fine? – Naoimi Apr 05 '19 at 20:58
  • Follow the link in my comment and you'll see if you've linked everything correctly it works – j08691 Apr 05 '19 at 20:59

1 Answers1

0

I can only just assume that your issue is that you are developing on your local machine and loading your HTML from your harddrive.

This question likely addresses your question;

Load local javascript file in chrome for testing?

What you are running into is called sandboxing and is that way for security reasons. It is concerning that IE does not display the issue actually.

This article has a good explanation of the need for your browser to be sandboxed.

Steve0
  • 2,233
  • 2
  • 13
  • 22