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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:59:37+00:00 2026-05-18T01:59:37+00:00

I have following generrated HTML, and I want to add some CSS class to

  • 0

I have following generrated HTML, and I want to add some CSS class to them from client-side with jQuery.

I’d like to add CSS class “user-active” to the following “” tag that has the text “Active”

<a id="ctl00_ContentPlaceHolder1_lvStudent_ctrl5_lnkStatus">Inactive</a>
<a id="ctl00_ContentPlaceHolder1_lvStudent_ctrl6_lnkStatus">Active</a>
<a id="ctl00_ContentPlaceHolder1_lvStudent_ctrl7_lnkStatus">Inactive</a>

I’d like to add CSS class “user-inactive” to the following “” tag that has the text “Inactive”

<span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl5_lblStatus">Inactive</span>
<span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl4_lblStatus">Active</span>
<span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl6_lblStatus">Active</span>

Thanks.

Updated HTML output inside the container:

<table cellspacing="1" class="time-sheet" id="TimeSheet">
<thead>
<tr>
    <td>
    </td>
    <td colspan="5">
    </td>
</tr>
<tr>
    <th>
        <a href="#">Name</a>
    </th>
    <th>
        <a href="#">Id</a>
    </th>
    <th>
        <a href="#">User name</a>
    </th>
    <th>
        <a href="#">Status</a>
    </th>
</tr>
</thead>
<tbody>
<tr>
    <td>
         Charlie Sansa
    </td>
    <td>
         210
    </td>
    <td>
        charlieb
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl0_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Rai Ninga
    </td>
    <td>
         211
    </td>
    <td>
        raiw
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl1_lblStatus">Inactive</span>
    </td>
</tr>
<tr>
    <td>
         Sokcheng Ima
    </td>
    <td>
         212
    </td>
    <td>
        sokchengu
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl2_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Khamkhong Ying
    </td>
    <td>
         213
    </td>
    <td>
        khamkhongt
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl3_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Monica Seth
    </td>
    <td>
         214
    </td>
    <td>
        monicat
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl4_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Andrew Donut
    </td>
    <td>
         215
    </td>
    <td>
        andrewm
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl5_lblStatus">Inactive</span>
    </td>
</tr>
<tr>
    <td>
         Jarn Maras
    </td>
    <td>
         216
    </td>
    <td>
        jarnt
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl6_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Juliette Buran
    </td>
    <td>
         217
    </td>
    <td>
        juliettec
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl7_lblStatus">Inactive</span>
    </td>
</tr>
<tr>
    <td>
         Sattaporn Lovin
    </td>
    <td>
         218
    </td>
    <td>
        sattapornw
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl8_lblStatus">Active</span>
    </td>
</tr>
<tr>
    <td>
         Surachard Karach
    </td>
    <td>
         219
    </td>
    <td>
        surachards
    </td>
    <td>
        <span id="ctl00_ContentPlaceHolder1_lvStudent_ctrl9_lblStatus">Active</span>
    </td>
</tr>
</tbody>
</table>
  • 1 1 Answer
  • 1 View
  • 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-18T01:59:38+00:00Added an answer on May 18, 2026 at 1:59 am

    If you had a container to restrict the search you could up the performance quite a bit, so this will work in all cases:

    $("a, span").addClass(function() {
      switch($.text([this])) {
        case "Active": return "user-active";
        case "Inactive": return "user-inactive";
      }
    });
    

    But something like this would make it much faster, by narrowing it down to looking at only <a> and <span> elements you care about:

    $("#TimeSheet").find("a, span").addClass(function() {
      switch($.text([this])) {
        case "Active": return "user-active";
        case "Inactive": return "user-inactive";
      }
    });
    

    We’re just using .addClass() in both cases to add the class based on the exact text, not a substring match. You could also map this in an object, for example:

    var classes = { "Active":"user-active", "Inactive":"user-inactive" };
    $("#TimeSheet").find("a, span").addClass(function() {
      return classes[$.text([this])];
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code similar to the following: In myapp.html <template name=problems> <div class=problems>
I have the following html generated through my PHP code. What I want to
if i was to have the following HTML: <div> <div> <div> <div> I want
Following on from some comments of late, I have took the plunge and started
I have a some html being generated by JQuery on a Share Point page.
i have the following URL (originally generated from SEO toolin OS Commerce) http://www.mydomain.com/-some-name-s-34567.html i
I have the following form: from models import MyModel class MultProgresemosReferenciasForm(forms.Form): selected = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple,
I have a web user control that generates the following html on the client.
i have the following file member.html.erb: <ul class=members-list> <%@members.each do |member|%> <li class=member-item> <%=member.name%>
I have several instances of the following HTML on a page: <div class=input radio

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.