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 993097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:21:59+00:00 2026-05-16T06:21:59+00:00

I am learning jquery and I am having difficulty running the following extremely simple

  • 0

I am learning jquery and I am having difficulty running the following extremely simple code.

My HTML looks like:

<html>
<head>
    <title>JQUERY</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
    <script type="text/javascript" src="script.js"></script>
</head>
<body>

<input type="button" id="testbutton" value="test" />

</body>

My script.js looks like this:

$(document).ready(function(){
  alert('document is ready');
});
$('#testbutton').click(function(){
  alert('button clicked');
});

When I load the page in browser … I get the first alert when the document is loaded (so I am sure that I am at least using the correct library and it is getting downloaded etc).

However, when I click my button I do not see the second alert that says “button has been clicked”

What am I missing?

  • 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-16T06:21:59+00:00Added an answer on May 16, 2026 at 6:21 am

    The click handler needs to go inside your $(document).ready, to ensure that it is bound when the DOM is ready, and the element is guaranteed to be available for Javascript processing:

    $(document).ready(function(){
        alert('document is ready');
    
        // bind a click handler to #testbutton when the DOM has loaded
        $('#testbutton').click(function(){
          alert('button clicked');
        });
    });
    

    From the documentation:

    This is the first thing to learn about
    jQuery: If you want an event to work
    on your page, you should call it
    inside the $(document).ready()
    function. Everything inside it will
    load as soon as the DOM is loaded and
    before the page contents are loaded.

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

Sidebar

Related Questions

As part of learning jQuery, I decided to do a simple tic-tac-toe game in
The book Learning jQuery says IE has memory leak for the DOM object having
Beyond the official documentation, are there any recommended resources for learning to build jQuery
I'm learning JavaScript and while browsing through the jQuery library I see : (colon)
Where is a good place to get started learning how to use jQuery? It
I am trying my hardest to learn jQuery with the Learning Jquery 1.3 Book
Ok I am still having some issues with this code below. I have received
Greetings. I'm having a weird problem with jQuery on my website. I'm trying to
I have just started learning Rails and I'm trying to build a post/like type
I am still learning jQuery and the selector bit is incredibly useful, but I

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.