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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:22:35+00:00 2026-05-27T04:22:35+00:00

I am working with jquery and attempting to add a class to a table

  • 0

I am working with jquery and attempting to add a class to a table on the selection of that table row.

I was initially using the following code –

$(this).parents("tr").toggleClass("over", this.clicked);            

For some reason, that wasn’t working in only some instances where there was already a class assigned.
Before I went too crazy with any troubleshooting, I changed it to the following –

$(this).parents("tr").addClass("over", this.clicked);           

This new option appears to be working fine.

My question is whether one option above is better than the other…..Should I be using toggleClass instead of addClass, or is addClass sufficient?

thanks for any thoughts.

  • 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-27T04:22:36+00:00Added an answer on May 27, 2026 at 4:22 am

    addClass does just that, adds the class to the element.

    toggleClass on the other hand does THAT, toggles the class, removing it if it’s there, otherwise adding it, but optionally taking a boolean value (true/false) to determine if the object should be added (true) or removed (false).

    toggleClass probably wasn’t working for you in the instances where this.clicked was false, which is expected behavior. The argument you’re passing in addClass has no effect, since it ALWAYS adds the class.

    Conclusion:

    Use toggleClass for toggling classes, use addClass for adding classes.

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

Sidebar

Related Questions

I am working on a simple web app using jquery mobile. I am attempting
I have a bit of HTML/JQuery code that only seems to be working for
I'm working on a page that has both Mootools 1.4 and jQuery 1.5.1 running.
I'm attempting to use 'jQuery Validate' on a form that requires an email address
Working jQuery, what I'd like to perform is something similar to the following: $('sometag').children().wrap('<div></div>');
I have jquery working in my Richfaces 3.3.3 application. I added the following to
I'm attempting at creating a menu from a table using the Suckerfish css menu
I have a list of options that looks like this: <select id=input_13> <option class=level-1
Working against jQuery 1.3.2 I'm looking for best practices that implement the typical '
I'm attempting to add this .click function to each image I'm sorting with the

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.