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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:43:11+00:00 2026-05-24T03:43:11+00:00

I have a html table which has several rows – lets say 17 for

  • 0

I have a html table which has several rows – lets say 17 for this example. On row 2, 9 and 15 I have some BOLD text which are basically headers for the rows after it. I’ve used the following code to add an IMAGE after each header:

$("#tblResults tr.lGreyBG td span.gridTXT b").each (function(index) {
    $(this).after("&nbsp;<img class='ChartButton' id='c"+ index +"'src='Images//chart_bar.png' alt='Chart' width='20' />");                 
});

I also have the following bit of code which binds a click event to each of the chart buttons.

$("img.ChartButton").click(function(){
    alert ($(this).attr("id")); // THIS LINE WILL BE REPLACED
});

At the moment, it simply displays the ID of the chart button. What I need to do is replace the alert to pull back the rows afters the header row that was clicked, upto the next header row, of until the end of the table, (whichever comes first). So if the first button was clicked then rows 3 to 8 will be pulled back. Once I have these I can then iterate through each of the TD cells to look at the data in the table.

Many thanks for any help on what “selectors” I need to use to pull back the correct rows. Also note that this needs to be dynamic as other tables will have different number of rows.

Thanks
H

  • 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-24T03:43:13+00:00Added an answer on May 24, 2026 at 3:43 am
    // notice that use after() directly, without each()
    $("#tblResults tr.lGreyBG td span.gridTXT b").after(function (index) {
        return "<img class='ChartButton' id='c"+ index +"'src='Images//chart_bar.png' alt='Chart' width='20' />";
    });
    
    $("#tblResults").delegate("img.ChartButton", "click", function () {
      var currentRows = $(this).closest("tr").nextUntil("tr:has(span.gridTXT b)");
    });
    

    BTW: You definitely should think about a more semantic markup using multiple <thead> and <tbody> tags if your table has multiple heads and bodies.

    $("#tblResults thead span.gridTXT b").after(function (index) {
        return "<img class='ChartButton' id='c"+ index +"'src='Images//chart_bar.png' alt='Chart' width='20' />";
    });
    
    $("#tblResults").delegate("img.ChartButton", "click", function () {
        var currentRows = $(this).closest("thead").next("tbody").find("tr");
    });
    

    Edit: Changed answer to use nextUntil().

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

Sidebar

Related Questions

I have a simple html table which has several rows. the following is implemented
I have a table row which has class='highlightedrows' within my html I am trying
I have HTML table with 10 rows and which has a Current Value column
I have an HTML table in which each data row has a unique id
I have this table where I can generate dynamic rows (which has input <type=text
I have a repeater control outputting some HTML. I want a table which outputs
I have a table with multiple tbody's, each of which has a classed row,
I have a Html Table which consists of rows that were generated dynamically (from
I have a table in which i append rows on onclick event, the row
I have a page with a table on it that has several thousand rows

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.