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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:38:27+00:00 2026-06-08T18:38:27+00:00

I am using jQuery’s event delegation to add a click event to table rows.

  • 0

I am using jQuery’s event delegation to add a click event to table rows. I also have a checkbox in the first td of the row. When I click anywhere in the row everything works as expected. However, I don’t want the event to work when I click in the checkbox. I’ve tried using the :not() selector but perhaps I am missing something as I am still triggering the event when I click in the checkbox.

HTML

<tr>
    <td>
        <div class="myCheckbox"><input type="checkbox" name="userName" /></div>
    </td>
    <td><a href="/go/to/user/profile"></a></td>
    <td>more info</td>
    <td>more info</td>
    <td>more info</td>
</tr>

jQuery

$('table tr:not(':checkbox')').on('click', 'td', function(event) {

    // Do something
});

Can I get help fixing what I am attempting to do please?

  • 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-08T18:38:28+00:00Added an answer on June 8, 2026 at 6:38 pm

    Two options (both involve removing the tr:not stuff from your existing code, which as you say doesn’t work — tr elements can’t be checkboxes, and :not checks the element, not its contents):

    1. Add an event handler to the checkbox that calls e.stopPropagation. Then the click event won’t reach the row. You can do that either directly or via delegation. Here’s a live example going direct. If you go indirect, be sure to test clicking labels that activate the checkbox (if you’re going to have them) on all of the browsers you intend to support.

      or

    2. Add this to your handler:

      if ($(event.target).is('input[type=checkbox]')) {
          return;
      }
      

      E.g.:

      $('table').on('click', 'td', function(event) {
      
          if ($(event.target).is('input[type=checkbox]')) {
              return;
          }
      
          // Logic here
      });
      

      That works by testing the source of the event to see if it’s a checkbox, and bailing early.

    In both cases, if you use a label to activate the checkbox, you may need to do the same thing for the label.

    I got curious about what #2 would look like handling labels, and it turns out it’s enough code to move into a function, but not hard &mdash probably how I’d go: Live example | source

    jQuery(function($) {
    
      // The table cell click handler
      $("table").on("click", "td", function(e) {
        // Is the source a checkbox or the label for
        // one?
        if (isCheckbox($(e.target))) {
          return;
        }
    
        // Normal handling
        $(this).toggleClass("foo");
      });
    
      // Function to test whether the source is a
      // checkbox, or the label of a checkbox
      function isCheckbox($elm) {
        var chkid;
    
        if ($elm.is("input[type=checkbox]")) {
          return true;
        }
        if ($elm.is("label")) {
          chkid = $elm.attr("for");
          if (chkid) {
            return $("#" + chkid).is("input[type=checkbox]");
          }
          return !!$elm.find("input[type=checkbox]")[0];
        }
        return false;
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jQuery, how do I delete all rows in a table except the first?
Using jQuery, how do you bind a click event to a table cell (below,
(using jquery) I have the following function $(function() { $('tr.parent') .css(cursor,pointer) .attr(title,Click to expand/collapse)
Using jquery, I currently append html to a div on a click event. The
Using jQuery I want to be able to click an element which will also
Using Jquery , I have an array result [<a href=><img src=image1></a>,<a href=><img src=image2></a>] if
Using jQuery, I make these changes in the DOM: $(document).ready(function() { $('.editable').click(function() { var
Using JQuery I am trying to perform validation and also get the values of
Using jquery I have a clicking tab mechanism that are nothing but anchor tags
Using jquery, how can I find the first div that contains an input with

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.