user1778543 user1778543 - 1 year ago 125
jQuery Question

Using jquery in js file

Okay so all I am trying to do is make the jquery work in my javascript file which is linked to a html file. I created a totally new file for this to test it. The whole contents of the html file are:

<!DOCTYPE html>
<script src="C:\Users\Me\Desktop\Programming\jquery-1.12.4" type="text/javascript"></script>
<script src="check.js"></script>
<head> <h1>test</h1>

And the whole content of the js file is

$("h1").css("color", "red");

But when I open the html file in chrome the change I put in the js file with jquery doesn't show up (e.g the heading is not red). I just want to figure out how to make it so that it does.


Thanks for the help everybody, I was able to make it work :)

Answer Source
  1. Move your <h1> tag to be in the <body>
  2. Move your <script> tags to the <head>
  3. Replace your code in your JS file with what imvain2 said, so that the JS will load once your document is ready.
  4. Make sure you are correctly referencing your jQuery script. You can even use this to test it out:

    <script src=""></script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download