Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:05:50+00:00 2026-05-30T13:05:50+00:00

Ok, so I recently started learning jQuery, but I’m having trouble with a little

  • 0

Ok, so I recently started learning jQuery, but I’m having trouble with a little animation program I got off of the jQuery website.
So here is the problem. This program works:

<HTML>
<HEAD>
<script type="text/javascript" src="javascript/jQuery-1.7.1.min.js"></script>

<STYLE type="text/css">

#content {
    background-color:#6688ff;
    position:absolute;
    width:100px;
    height:100px;
    padding:3px;
    margin-top:5px;
    left: 100px;
}
</STYLE>
</HEAD>
<BODY>
<input type="button" id="left" value="Left"/>
<input type="button" id="right" value="Right"/>
<div id="content">Move</div>
<script type="text/javascript">
$("#right").click(function() {
    $("#content").animate(
            {"left": "+=50px"},
            "slow");
});
$("#left").click(function() {
    $("#content").animate(
                {"left": "-=50px"},
            "slow");
});
</script>

</BODY>
</HTML>

But this program doesn’t:

<HTML>
<HEAD>
<script type="text/javascript" src="javascript/jQuery-1.7.1.min.js"></script>

<script type="text/javascript">
$("#right").click(function() {
    $("#content").animate(
            {"left": "+=50px"},
            "slow");
});
$("#left").click(function() {
    $("#content").animate(
                {"left": "-=50px"},
            "slow");
});
</script>

<STYLE type="text/css">

#content {
    background-color:#6688ff;
    position:absolute;
    width:100px;
    height:100px;
    padding:3px;
    margin-top:5px;
    left: 100px;
}
</STYLE>
</HEAD>
<BODY>
<input type="button" id="left" value="Left"/>
<input type="button" id="right" value="Right"/>
<div id="content">Move</div>


</BODY>
</HTML>

The only difference between the two programs is where I put the javscript, so could anyone explain me why that makes a difference? Thanks, cause that is confusing me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:05:51+00:00Added an answer on May 30, 2026 at 1:05 pm

    The document isn’t ready when the second jQuery code chunk runs, so it doesn’t work.

    Always wrap your jQuery code in a $(document).ready() statement:

    $(document).ready() {
      $("#right").click(function() {
        $("#content").animate({"left": "+=50px"}, "slow");
      });
    
      $("#left").click(function() {
        $("#content").animate({"left": "-=50px"}, "slow");
      });
    });
    

    Your second code chunk is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started learning jQuery and I think I'm in love :) Here's what
I recently started learning Clojure and I'm having a bit of difficulty wrapping my
I have recently started learning C++, but I require a compiler. I have tried
I've recently started learning OpenGl through the SB fifth edition, unfortunately got stuck right
I just recently have started learning about the wonders of **kwargs but I've hit
I've recently started learning Scala and was disappointed (but not surprised) that their generics
I've recently started learning how to use MFC in Visual Studio. My program uses
Having only recently started learning the 'new' OpenGL (programmable as opposed to fixed-function, I
I recently started learning open source technologies and very soon got frustrated as there
I started learning Django recently and am having a strange problem with the tutorial.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.