Why won't my jQuery code work on an external site?



Okay, so I used the example from: intro to jQuery
I'm not understanding why the jQuery does not work outside of Codecademy. My HTML and CSS work just fine. But when I hover over the button, nothing happens. Can someone please point me in the right direction? Thank you.

My file names:
- HTML: index.html
- CSS: style.css
- jQuery: script.js



<title> Testing jQuery </title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
<script type="text/javascript" src="script.js"></script>
<link rel='stylesheet' type='text/css' href='style.css'/>


<div> <br /> <strong> Click Me! </strong> </div>


The CSS:

div {
    height: 600px;
    width: 1000px;
    border-radius: 5px;
    background-color: #69D2E7;
    text-align: center;
    color: #FFFFFF;
    font-family: Verdana, Arial, Sans-Serif;
    opacity: 0.5;

The jQuery:

$(document).ready(function() {
    $('div').mouseenter(function() {
        $('div').fadeTo('fast', 1);
    $('div').mouseleave(function() {
        $('div').fadeTo('fast', 0.5);


where is your button?



Hi Nick,

Your code looks fine to me. Could you try replacing your current JavaScript code with this instead:

$(document).ready(function() {
  try {
    $('div').mouseenter(function() {
      $('div').fadeTo('fast', 1);
    $('div').mouseleave(function() {
      $('div').fadeTo('fast', 0.5);
  } catch(error) {

and tell me if you get a popup telling you about an error when you reload the page to visit it again? Thanks :slight_smile:


I don't understand your question. The one and only bit of html I have the is the button div, if that's what you meant.


where did you try to run?



I had all three files in a folder and I tried to run the HTML file on three different browsers: chrome, ie, and firefox. all to no avail.


I think I figured it out. While I was at school, it wasn't working and I know for a fact that we have somewhat limited access with the various firewalls and whatnot, so maybe for some reason jQuery doesn't mix well with said firewalls. At home now though, it works completely fine, only reinforcing my thoughts.


fyn :slight_smile:


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.