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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:21:41+00:00 2026-05-31T16:21:41+00:00

I have a div inside a table cell. When I click in the table

  • 0

I have a div inside a table cell. When I click in the table cell on the div, the click event isn’t trigged, it seems like that table cell is on top of the div? I have tried adjusting the z-index to no avail.

Example row:

<tr ><td><div class="test" style='width:64px; height:22px; margin:0 auto; z-index:1000'></div></td></tr>

Example jquery:

$('.test').click(function(){
        console.log($(this), 'this');
    });

Update: The div in my table row is added dynamically after the document is loaded and the jquery code is in the .ready part of my code perhaps that is 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-05-31T16:21:42+00:00Added an answer on May 31, 2026 at 4:21 pm

    The key to your question is in your recent comment:

    The div in my table row is added dynamically after the document is loaded and the jquery code is in the .ready part of my code perhaps that is why?

    When you run your code, which hooks up the handler directly on elements, it will hook the click event only on elements matching the selector that already exist. Elements you add later won’t be hooked up.

    If you want your code to handle elements that are added later, you probably want to use event delegation. jQuery supports this via the delegate function or (if you’re using 1.7 or later) the delegating form of on:

    // Using `delegate`:
    $("selector_for_some_container").delegate(".test", "click", function() {
        console.log($(this), 'this');
    });
    
    // Using `on` (v1.7 or later, note that the arguments are in a different order):
    $("selector_for_some_container").on("click", ".test", function() {
        console.log($(this), 'this');
    });
    

    What those do is hook the click event on some container (in your case you might use the table), and when the click reaches that container, jQuery checks to see if it traveled through an element matching the selector you give. If so, jQuery fires the event as though you’d hooked click on the element itself.

    Here’s an example (live copy | live source):

    HTML:

    <p>The "static" div below exists before we hook up our
    event handlers; the "dynamic" one is adding after.
    Click each of them to see which handlers fire.</p>
    <table id="theTable">
      <tbody>
        <tr><td><div class='test' style='width:64px; height:22px; margin:0 auto; z-index:1000'>static</div></td></tr>
        <tr><td id="target"></td></tr>
      </tbody>
    </table>
    

    JavaScript:

    jQuery(function($) {
    
      // Note that the div doesn't exist yet, so this won't
      // hook it up
      $(".test").click(function() {
        display("Direct click handled on " +
                this.innerHTML
               );
      });
    
      // This form uses event delegation. Note that the div
      // still doesn't exist.
      $("#theTable").delegate(".test", "click", function() {
        display("Delegated click handled on " +
                this.innerHTML
               );
      });
    
      // Add the div
      $("#target").html(
        "<div class='test' style='width:64px; height:22px; margin:0 auto; z-index:1000'>dynamic</div>"
      );
    
      function display(msg) {
        $("<p>").html(msg).appendTo(document.body);
      }
    });
    

    Alternately, of course, you can always hook up the event on the element when you’re adding it. But if you’re adding and subtracting elements from a container, event delegation is usually (not always) the way to handle events on them.

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

Sidebar

Related Questions

In the second table cell I have a div inside of it that I
Float:right specified for a div inside a table cell seems to have no effect
I have a div tag inside a table cell and and a hyperlink tag
I have a layout that looks like this: It's a table with one cell
I have a table and want to include a div inside it such that
I have a div inside of a table which is inside of a form
I have a div that has a span inside that will display a message
I have articles with display:table and an image wrapper inside with display:table-cell to achieve
I have a large table with with each cell being 25x25 and a div
I have a table inside a DIV , but the div height and width

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.