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

jquery

#1

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


The HTML:

<html>
<head>

<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'/>
</head>

<body>

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

</body>
</html>

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);
    });
});

#2

where is your button?

@nickgrimes50


#3

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) {
    alert(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:


#4

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.


#5

where did you try to run?

@nickgrimes50


#6

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.


#7

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.


#8

fyn :slight_smile:
@nickgrimes50


#9

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