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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:26:32+00:00 2026-06-16T21:26:32+00:00

Click event with jquery function is not working when it is before the a

  • 0

Click event with jquery function is not working when it is before the a tag but it is working fine after the a tag. Also, if I use document.ready then it works. I would like to know why it is not working when it is before the a tag.

<head>
    <script type="text/javascript">
        function jchand(){
            $('a').click(function(){
                alert('a')
            })
        }
        jchand();
    </script>
</head>
<body>
    <a href="#" >click me</a>
</body>
  • 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-16T21:26:33+00:00Added an answer on June 16, 2026 at 9:26 pm

    The element doesn’t exist when you try to bind .click, as the page has not yet finished loading.

    another thing If i am using document .ready then it is working

    Well, this is exactly what $(document).ready is for:

    $(document).ready(function()
    {
        $('a').click(function()
        {
            alert('a');
        });
    });
    

    Alternatively, you could use .on():

    $(document).on('click', 'a', function()
    {
        alert('a');
    });
    

    which binds to the entire document instead, and so will work for any elements added in the future.

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

Sidebar

Related Questions

How do I fade in an element after using jquery's .before? jQuery $('.button').on(click, function(event){
I have a problem of jQuery's live() function not working with click, mousedown but
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //
I am using jQuery to attach a function to my click event for an
Javascript jQuery event handling If on event (for example 'click') bound one function for
All, I've got the following code: var site_url = 'http://localhost/website/'; jQuery(#cancel_song_choice).click(function(event){ cancel_url = site_url
How can i stop propagation for link? <script src=http://code.jquery.com/jquery.min.js></script> <script> $(function() { $(#g).click(function(event){ alert(Link
Here is my JavaScript: <script> //Make sure DOM is ready before mucking around. $(document).ready(function()
After appending table I am checking on button click event. Javascript alert is working
I have this working on local setup (with jquery.1.6.4) but it is not working

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.