Ethan Leyden
Ethan Leyden

Reputation: 298

Javascript not running in Chrome

It's been a while since I've touched web development, and I'm trying to get back into it. For some reason, however, I seem to be having trouble getting my JS scripts to run. I've tried linking a JS file using <script src="script.js"></script>, and even though the script file is in the same directory as my index.html, it seems to be ignoring it entirely. I've got some event listeners from jQuery, but at the very beginning of the code is a console.log("sanity check");.

So, after that didn't work, I tried writing the script directly in the html file like so:

<script>
     console.log("WHAT IS GOING ON?!");
     alert("It's finally working!");
</script>

and that STILL didn't work. Help!

Edit:

Here is the relevant HTML:

<head>
    <script src="jquery-3.4.1.min.js"></script>
    <script src="script.js"></script>
    <script>
      console.log("WHAT THE CRAP IS GOING ONNNN");
      alert("JS is running");
    </script>
</head>

Here is the JS,

console.log("sanity check");
$(document).ready(function() {
  console.log("Helloooo and good moonring!");
  $("#back").hover(function() {
    console.log ("*eyeroll* YES. I can hear you.");
    $("#back").attr("cursor", "pointer");
  }, function() {
    $("#back").attr("cursor", "default");
  });
});

None of it is working. I'm running it locally. The inspect tool in Chrome shows no errors whatsoever.

Edit 2:

I took a closer look at the code in the inspect tool. Still, nothing seeming to be wrong with it, but I have noticed that it isn't updating to the saved changes upon refreshing the page. This is clearly problematic, and very confusing. Also added type="text/javascript" and changed script.js to ./script.js (and the same with the jQuery file).

Upvotes: 0

Views: 2186

Answers (2)

Ethan Leyden
Ethan Leyden

Reputation: 298

Solved! Earlier, before I came across this issue, I decided to change my folder from "Web Design Project" to "WebDesignProject", because there were some things I wanted to look at in Terminal. Apparently my text editor, Atom, decided that this meant that the folder I had left open called "Web Design Project" was an entirely different folder. Those changes that I made were then mapped not to "WebDesignProject," but instead a new folder, once again named "Web Design Project."

In conclusion. Never put spaces in your project folder name. And, when you change the folder name, restart EVERYTHING. Atom should fix this phenomenon.

Upvotes: 1

Will
Will

Reputation: 3241

This snippet works, no?

<script>
  console.log("WHAT THE CRAP IS GOING ONNNN");
  alert("JS is running");
</script>

Make sure these are checked and messages aren't hidden. Also maybe change "console.log" to "alert" just to make sure but check to make sure messages aren't being filtered out.

Chrome Console Filter

Upvotes: 1

Related Questions