Codebits and jQuery


#1

Hi folks,

I have been playing with jquery in the codebits but it doesn't seem to work.

In my scripts.js file - A simple alert to test if is working but it doesn't work?

$(document).ready(function(){
     alert("hello");
});

In the header file of my HTML

http://code.jquery.com/jquery-1.9.1.min.js

I cannot add the script tags here in the forum?! Anyway that is not the issues, my jQuery is not working!

Please help :smile:


#2
$(document).ready(function() {
    alert("hello");
});

For me your Code works fine.

Please refresh the browser and maybe clear the cache.


#3

Hey Benjamin,

There are two common problems people have getting started using jQuery on their own:

  1. Not linking to jQuery at all. It looks like you're doing that, just make sure it looks like this:

    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  2. Or, linking to jQuery after the link to their other script. You need to link to jQuery before, like so:

    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="script.js"></script>

Are you doing both of those properly?

EDIT:

Oh, and I forgot to mention: the reason your <script> tags are getting stripped out of the post is because Markdown (the formatting language this forum uses) automatically strips out all HTML tags as a security precaution. If you want to show a small part of code (like <script>), you just surround your code with a backtick (`) on either side. And for a block of code like above, you surround it with a new line and three backticks before and after. Example:

# blank line
``` # three backticks
# block code goes here
``` # three backticks
# blank line

# small bit of code: `<script>`

I hope this helps :)