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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:03:37+00:00 2026-05-23T20:03:37+00:00

I have a table with a bunch of data. Each <td> contains class="person" and

  • 0

I have a table with a bunch of data. Each <td> contains class="person" and id=0,1,2,3, etc. based on $i (I’m using a loop to build my table from an array).

I’d like it so that whenever a person (<td>) is clicked, that cell gets highlighted with some css.

So far I think I can use this:

$(‘.person’).click(function(){

$id = some function to which attr('id') was selected???;
$('id').addClass("highlights");

});

Does anyone know how I can fetch the ID of the cell being clicked? Any help or approaches appreciated.

Thanks!

  • 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-23T20:03:38+00:00Added an answer on May 23, 2026 at 8:03 pm

    this.id refers to the id of the td inside the method.

    $('.person').click(function(){
    
        var id = this.id;
        $('#' +id).addClass("highlights");
    
    });
    

    But if you want to just change something on the element, then you do not really need the id. That is because the this keyword refers to the actual clicked element.

    So you can directly do

    $('.person').click(function
        $(this).addClass("highlights");
    });
    

    Beware, though, that the id of an element cannot be numeric (as far as valid html is concerned..)

    And i quote

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”).

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

Sidebar

Related Questions

I have to copy a bunch of data from one database table into another.
I have a table where each row contains some data ( data-id ) and
i have a table which contains a bunch of dynamically created radio button lists,
I have a table that contains a VARCHAR2 column called COMMANDS. The data in
I have a script to extract certain data from a much bigger table, with
I'm using Quartz.NET to schedule a job which loads a bunch of data from
I have to create a query that compiles a bunch of data for each
I have a table (MySQL) data that stores a bunch of signup information. What
I have a table with unique usernames and a bunch of string data I
I have a table containing a bunch of input fields, sort of like a

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.