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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:31:24+00:00 2026-05-31T21:31:24+00:00

I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>

  • 0

I have a table structure like this:

<table>
  <tr>
    <td>
      <ul>
        <li class="check"></li>
      </ul>
    </td>
    <td>
      <ul>
        <li class="check"></li>
        <li class="check"></li>
      </ul>
    </td>
  </tr>
</table>

My goal is, on click within a table cell, another li element is added to the single ul within each cell. When clicking ON the li element, the last li in the cell’s ul is removed.

Here is the jq I tried:

$(document).on("click", "table tr td", function() {
   var parul = $(this).children("ul");
   $('<li class="check">&nbsp;</li>').appendTo(parul);
});

$(document).on("click", "li.check", function(){
   $(this).siblings(":last").remove();
});

The table is being generated by jQ dynamically, so I’m trying to avoid using IDs in my selectors. Also why I’m using .on(), since as I understand, it will apply to LIs that don’t necessarily exist yet (please correct me if I’m understanding that incorrectly!).

I’ve found that the above 2 functions work independently, but when I uncomment both of them, only the “adding” function works, the remove doesn’t.

I’m new to jQ, so this is a real mystery. If there’s a totally different solution that accomplishes the same goal, I wouldn’t mind, but for learning purposes, I’d also like to understand why my code isn’t working as I expected.

Thanks in advance!

  • 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-31T21:31:25+00:00Added an answer on May 31, 2026 at 9:31 pm

    When you click on the li, the td registers a click as well. You need to add stopPropagation() on the li handler:

    $(function() {
        $(document).on("click", "li.check", function(e) {
            $(this).siblings(":last").remove();
            e.stopPropagation();
        });
    
        $(document).on("click", "table tr td", function() {
            var parul = $(this).children("ul");
            $('<li class="check">&nbsp;</li>').appendTo(parul);
        });
    });
    

    Demo: http://jsfiddle.net/uLCRd/

    This will prevent the second handler from being called once the li click is handled.

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

Sidebar

Related Questions

i have structure like this <table><tr><td></td><td><input type=button name=button></td></tr></table> <script> $('tr').click(function(){window.alert('tr');}) $(':input').click(function(){window.alert('input');}) </script> when i
I have a table that has structure like this (td omitted) <table> <tr class=header>...</tr>
If I have a table structure like this: Transaction [TransID, ...] Document [DocID, TransID,
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I currently have a table structure that looks something like this(some details omitted): ColumnName
I have this table structure and would like to map it using Fluent Hibernate
I have a table structured like this: <table> <tr id=id1 class=parent></tr> <tr class=id1></tr> <tr
I have a C++ key/value table that looks like this: class kvBucket { ...
I have a simple one-to-many structure like this: class User(db.Model): userEmail = db.StringProperty() class
I have an existing table structure that looks something like this: AnimalTable ------------- |Id

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.