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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:33:36+00:00 2026-06-12T06:33:36+00:00

If I had two html tables like so: <table id=myTable> <thead> <tr> <th>First Name</th>

  • 0

If I had two html tables like so:

<table id="myTable">
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Age</th>
      <th>Total</th>
      <th>Discount</th>
      <th>Difference</th>
      <th>Date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Peter</td>
      <td>Parker</td>
      <td>28</td>
      <td>$9.99</td>
      <td>20.9%</td>
      <td>+12.1</td>
      <td>Jul 6, 2006 8:14 AM</td>
    </tr>
    <tr>
      <td>John</td>
      <td>Hood</td>
      <td>33</td>
      <td>$19.99</td>
      <td>25%</td>
      <td>+12</td>
      <td>Dec 10, 2002 5:14 AM</td>
    </tr>
  </tbody>
</table>
<br/><br/>
<table id="anotherTable">
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>High Score</th>
      <th>Total Score</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Clark</td>
      <td>Kent</td>
      <td>18</td>
      <td>32</td>
    </tr>
    <tr>
      <td>Bruce</td>
      <td>Almighty</td>
      <td>45</td>
      <td>180</td>
    </tr>
  </tbody>
</table>

jQuery on my HTML page:

$(document).ready(function(){
  $("#myTable").myplugin();
});

I am creating a jQuery plugin which I want to be able to apply to any or all HTML tables on a page in my application with either $(“table”).myplugin() or $(“#myTable”).myplugin().

in my plugin code:

return this.each(function(index){
    // code here
});

If I add the line $(this).addClass('myClass') the CSS “myClass” is added to table “myTable” but if I add the line $('thead').addClass() “myClass” is added to both theads. I’ve tried $(this thead).addClass(), $(this 'thead').addClass(), $('this thead').addClass() but the all throw a JS error. How do I utilize “this” to select only the thead in element “myplugin” is being applied to in this case “myTable”?

  • 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-12T06:33:37+00:00Added an answer on June 12, 2026 at 6:33 am

    You could use the .find method[jQuery docs].

    $(this).find("thead").addClass();
    

    If you are certain that thead is an immediate child of this, you can use .children instead and it would be faster, especially if you have very large tables.

    $(this).children("thead").addClass();
    

    You could also set this as the context for your query:

    $("thead", this).addClass();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I had two tables, users and blocked_users , how would I define the
Originally I had two tables in my DB, [Property] and [Employee]. Each employee can
NOTE: I had two variables with the same name... Big thanks to Stefan Birladeanu
Say I had the two tables below, how do I find all questions with
I have a html code in which i had two javascripts. I want to
In scrapy for example if i had two URL's that contains different HTML. Now
The ggplot2 manual at http://had.co.nz/ggplot2/scale_manual.html suggests using a structure like: values = c(8 =
I had two separate interfaces, one 'MultiLingual' for choosing language of text to return,
I've initially had two branches: master A---B---C \ fork D---E---F---H---I So I wanted to
If you had two snippets: (global-set-key \C-d delete-char) and (define-key global-map \C-d delete-char) Is

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.