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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:11:34+00:00 2026-05-23T10:11:34+00:00

I need to go through array and add it’s values as table rows classes

  • 0

I need to go through array and add it’s values as table rows classes where table cells has “colspan=10”.

Here is my html:

<tbody>
<tr>
    <td><a href="#"><img src=""></a></td>
    <td width="100%" align="left" colspan="10"><a href="#">Anchor</a></td>
</tr>
<tr>
    <td colspan="1" class="text"><img></td>
    <td valign="top" nowrap="" align="right"><a href="#"><img src=""></a></td>
    <td width="100%" align="left" colspan="9" class="smalltext"><a href="#" class="dottedlink">Anchor</a></td>
</tr>
<tr>
    <td colspan="1" class="text"><img></td>
    <td valign="top" nowrap="" align="right"><a href="#"><img src=""></a></td>
    <td width="100%" align="left" colspan="9" class="smalltext"><a href="#" class="dottedlink">Anchor</a></td>
</tr>
<tr>
    <td><a href="#"><img src=""></a></td>
    <td width="100%" align="left" colspan="10"><a href="#">Anchor</a></td>
</tr>
</tbody>

Please help! I’m totally new in jquery

PS I can add the same class but not from array

  • 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-23T10:11:35+00:00Added an answer on May 23, 2026 at 10:11 am

    This should do what you are asking for

    var classes = ['one', 'two', 'three', 'whatever']; // <-- your class array
    
    var $cells = $('td[colspan=10]');  // <-- selects table cells with colspan=10
    
    $cells.each(function(index, element){  // <-- executes this function for each cell in the $cells list
        var row = $(element).parent('tr');  // navigate to parent element <tr>
        row.addClass( classes.shift() ); // <-- shift() removes and returns first element in the list
        //   ^-- addClass adds the string as a class without removing previous classes
    });
    

    Of course that is for educational purposes. In real life you would write the same code more concisely:

    var classes = ['one', 'two', 'three', 'whatever'];
    $('td[colspan=10]').each(function(index, element){
        $(element).parent('tr').addClass(classes.shift());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to move backwards through an array, so I have code like this:
I need to iterate through the fields on a table and do something if
I need to simply go through all the cells in a Excel Spreadsheet and
I am trying to load a html page through UIWebview.I need to disable all
I need to sort through an array and sort each individual row in array
I need to loop through all the matches in say the following string: <a
I need to iterate through the items (strings) in a CComboBox to check which
I've been working on a project where I need to iterate through a collection
I need to create feature which will iterate through all subsites of site collection
I need an associative container that makes me index a certain object through 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.