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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:19:19+00:00 2026-06-11T10:19:19+00:00

this is a simple html file: <!DOCTYPE html> <html> <head> <title>Test Uploading Func.</title> <script

  • 0

this is a simple html file:

<!DOCTYPE html>
<html>
   <head>
<title>Test Uploading Func.</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery-1.7.2.js">                  </script>        
<link type="text/css" href="jquery-ui-1.8.21.custom.css" rel="Stylesheet" />
    <script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>

        <!--Include js file-->
        <script type="text/javascript" src="upload.js" ></script>
</head>
<body>
    <button id="Upload" value="upload">upload</button>      
    <script type="text/javascript" src="upload.js" ></script>
</body>

And this is the js file I want to include:

$( '#Upload' ).bind('click', function(){
alert(">");
});

If I just include the js file in the beginning, the selector # can’t know the id Upload so that I have to include it again
at the end of the file… I do know it’s not correct. But I don’t know how to resolve it? Don’t we just include all the js file within the tag head?
What’s the appropriate coding style I show have?
Thanks.

UPDATE question!!!

If I have a lot of scenario like this, should I add “$(document).ready()” to all the functions? A little weird…
Still another approach? Or web developers always do so.

And where should I include my js file? In the begin or the end?

If I include them all in the end, this kind of problem won’t appear.
Then why lots of people include the js file just in the start?

  • 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-11T10:19:21+00:00Added an answer on June 11, 2026 at 10:19 am

    Wait for the DOM to be ready before selecting elements:

    $(document).ready(function () {
        $( '#Upload' ).bind('click', function(){
            alert(">");
        });
    });
    

    Update:

    You should always use $(document).ready(...) if you are manipulating elements that you expect to be on the page when your code runs. This is especially important if your code is in the <head></head> of the document.

    You are not required to use $(document).ready(...) if your code is inside the </body> tag, but be aware that there are differences between the two.

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

Sidebar

Related Questions

I have this simple piece of HTML code: <div> <input type=file name=english-file /> </div>
This is my code inside smarty tpl file(or for any simple HTML): <img src=../images/blah.jpg
To test I saved this html file to my server. Is there a simple
I have these (sample) lines in a HTML-file: test.ABC.test test.ABCD.test test.ABCE.test And this Ant
Suppose I get, on a page, this simple html/script : <a id=hey href=#>try</a> var
I wrote a simple html file with just a javascript function. It worked in
Why is this simple HTML document not working right? What have I missed? I
So I have this simple HTML: <span id=badge>0</span> I want the number 0 to
I have this simple html: <div class=wrapper> <span class=higher> [higher] <span class=lower> hello </span>
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>

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.