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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:39:02+00:00 2026-06-05T13:39:02+00:00

I was using the $.click() method for triggering some events. But then I needed

  • 0

I was using the $.click() method for triggering some events. But then I needed to set some events for some HTML elements before the elements were declared. Let’s take this as an example:

<script>
    $('div.hide').click(function() {
        $('div.hide').css({'display' : 'none'});
     });
</script>
<div class="hide">some text</div>

The downside is that when setting the .click() method, the div.hide elements doesn’t exist, so no trigger is set.

So I turned to the .on() method, like so:

<script>
    $('div.hide').on('click', function() {
        $('div.hide').css({'display' : 'none'});
    });
</script>
<div class="hide">some text</div>

But this also doesn’t work. I thought calling .on() would make all existent and future div.hide elements trigger the 'click' function().

I managed to get past this inconvenience, but for my own knowledge I’d like to know what was I doing wrong. Is there no way to assign a trigger to future HTML elements?

My solituion was:

<script>
    $(document).ready( function() {
        $('div.hide').click(function() {
            $('div.hide').css({'display' : 'none'});
        });
    });
</script>
<div class="hide">some text</div>
  • 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-05T13:39:03+00:00Added an answer on June 5, 2026 at 1:39 pm

    You missed the three-argument version:

    $('body').on('click', 'div.hide', function() { ... });
    

    That puts the handler on the <body> but it catches the events that bubble and invokes the handler when the target element matches the selector (the second argument).

    The handler doesn’t have to go on the <body>; it can be any parent container element of your <div>.

    The “on” method replaces the older “live” and “delegate” methods, as well as “bind” itself.

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

Sidebar

Related Questions

I disabled the click event of image using unbind method. But I don't know
I am using maven, when I click some method of JDK from Eclipse, I
As I created a Progress bar using below code in a on click method
I have some dropdown menus that are display:none and only show upon click (using
When using the IE driver with IE9, occasionally the Click method will only select
I am currently using jQuery .click() method to update 15 text fields with simple
I'm using the click event on the TreeView to do some stuff when a
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal
I'm giving a user a link to download a csv file ...just using Click
I'd like to grow a view with each click using a ScaleAnimation. I've managed

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.