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

  • SEARCH
  • Home
  • 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 9150959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:41:05+00:00 2026-06-17T11:41:05+00:00

This is an example of click button to pop up an alert. <script type=text/javascript

  • 0

This is an example of click button to pop up an alert.

<script  type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>

If the above part is put in head part, it works.
If the above part is put like below, it does not work.
enter image description here

This drives me crazy since in an open source code, the author said that if the script source is put at the end of html, the page will load faster. I spent a lot of time to figure out why the source code do not work and I found out that the reason in the position of the script src part.

However, when I test on
http://jsfiddle.net/eSud7/3/
the position of the script is not important.

Could anybody please explain why?

I am using Google App Engine and tested on Firefox browser.

Additional info: I am using this free template. Please download and check the index.html,
The author put all script source at the end of document and it works. Why???????

  • 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-06-17T11:41:06+00:00Added an answer on June 17, 2026 at 11:41 am

    Yes its true that you should include your script at the bottom of the page, In your case you are calling jquery function even before core library has loaded. You will have to include your script after jquery library because functions are defined in the library and as the code executes these function has to be referenced

    //At the bottom of the page
    <script  type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
    </script>
    
    <script>
    
          $(document).ready("#button").click(function() {
          alert('button clicked');
    });
      </script>
    

    However, when I test on http://jsfiddle.net/eSud7/3/ the position of the script is not important.

    Thats because you have selected to load jquery library on load(Look at the left hand side), so your library is included in the DOM on body load i.e. in your fiddle your giving position of library is redundant

    Update on OP comments

    <script>
        $(document).ready("#button").click(function() { //Included at the header, jquery object like $ and function like ready not declared yet !!!
          alert('button clicked');
        });
      </script>
    

    AT the bottom of the page

    //Contains all the jquery functions
        <script  type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
            </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
I use this script multiple times to hide some text: $(document).ready(function(){ $(#button_to_click_to_toggle).click(function(){ $(#hidden_div).slideToggle(medium); });
Consider this example: Private Sub Button_Click( sender As Button, e As RoutedEventArgs) Handles btn.Click
Is this possible? example: $('a.change').click(function(){ //code to change p tag to h5 tag });
Ok, in my code I have for example, this: $('.follow').click(function(){ var myself = $(this);
This example working great because here containment is body http://jsfiddle.net/roXon/hMmbK/2/ when i use container
This example shows what I am trying to do: http://jsfiddle.net/Dqjvy/ I would like it
In this very simplified and minimized example click event handler has been defined for
I'm new to JavaScript and jQuery. I want to click a button and have
I would like have a button and when you click this button, un can

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.