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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:19:28+00:00 2026-06-18T03:19:28+00:00

If a table is defined so: <colgroup> <col style=width:100px;> <col style=width:100px;> </colgroup> <thead> <th

  • 0

If a table is defined so:

            <colgroup>
             <col style="width:100px;">
             <col style="width:100px;">
            </colgroup>
            <thead>
             <th class="foo" data-info="zipcode10023">
             <th class="foo" data-info="zipcode60602">
            </thead>

such that the value in custom attribute data-info is unique, when a cell in the table has been clicked, what is the most efficient way to determine which column has been clicked (i.e. in order to get the data-info value, e.g. “zipcode60606”) ?

EDIT: there may be invisible columns to the left of the clicked-on cell.

  • 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-18T03:19:29+00:00Added an answer on June 18, 2026 at 3:19 am

    Assuming that the click is detected on a cell:

    $('td').click(function(){
        var col = $(this).index(),
            dataInfo = $('thead th').eq(col).attr('data-info');
            /* or:
            dataInfo = $('thead th').eq($(this).index()).attr('data-info');
               or:
            dataInfo = $('thead th').eq($(this).index()).data('info');
            */
    });
    

    JS Fiddle demo using: $('thead th').eq(col).attr('data-info').

    JS Fiddle demo using: $('thead th').eq($(this).index()).attr('data-info').

    JS Fiddle demo using: $('thead th').eq($(this).index()).data('info').

    You could, of course, place the event-handler on an ancestor element, such as the tr, with either:

    $('tr').click(function (e) {
        var dataInfo = $('thead th').eq(e.target.cellIndex).data('info');
        console.log(dataInfo);
    });
    

    JS Fiddle demo.

    (Note that, ordinarily, event.target isn’t necessarily cross-browser compatible, and Internet Explorer may require (outside of jQuery) an alternative: window.event.srcElement, however jQuery normalizes the events, so that not only will IE read/’understand’ the event (and not require window.event instead) but it will also have access to the normalzed event.target.)

    Or, to use enough jQuery:

    $('tr').on('click', 'td', function (e) {
        var dataInfo = $('thead th').eq($(this).index()).data('info');
        console.log(dataInfo);
    });
    

    JS Fiddle demo.

    In much the same way the click can also be bound to the table element:

    $('table').click(function (e) {
        var dataInfo = $('thead th').eq(e.target.cellIndex).data('info');
        console.log(dataInfo);
    });
    

    JS Fiddle demo.

    References:

    • attr().
    • click().
    • data().
    • eq().
    • index().
    • jQuery event object.
    • on().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table defined as follows in HTML: <table border=0 cellpadding=0 cellspacing=0 style=width:100%;>
I have a declarative table defined like this: class Transaction(Base): __tablename__ = transactions id
I have a typical Persons table and an Orders table defined in such a
I have a table defined: <div id=display> <div class=displayRow> <img src=images/expand-arrow.gif class=expandArrow alt=expand> <div
Using MySQL version 5.5.28, I have a table defined as such: CREATE TABLE IF
I have a table defined as <table border=1 width=200px height=auto> <tr> <td></td> </tr> </table>
I have the following table defined through code-first: public class Action { public int
Say I have a table defined such that: Entities has_many Images Images has_one Entity
I have a table defined as <table width=600 cellspacing=0 cellpadding=0> <table border=0 cellspacing=0 cellpadding=25
Let's say we have a simple table defined as: <p:dataTable value=#{testBean.dummyStringData} var=data> <p:column> <p:commandLink

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.