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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:57:50+00:00 2026-06-06T07:57:50+00:00

My Javascript is quite basic, but for some reason I am having trouble. I

  • 0

My Javascript is quite basic, but for some reason I am having trouble. I have a table that is dynamically being built and the goal of my script is to select the last 5 rows if there are more then 10 total rows and apply a CSS style to those final five. I built a stripped down example where the first 5 rows should be made blue and the last 5 rows made red. http://jsfiddle.net/helpinspireme/3zCp8/

There is probably a much better way to do this. Any help would be appreciated.

ANSWER:
Using slice() allowed me to accomplish my goal. That can be seen here: http://jsfiddle.net/helpinspireme/3zCp8/ Thank you Kevin B.

  • 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-06T07:57:58+00:00Added an answer on June 6, 2026 at 7:57 am

    For what you explained you are trying to do in your question, the simplest way to accomplish it is:

    var rows = $("table.primary_table > tbody > tr");
    if (rows.length > 10) {
        rows.filter(":lt(5)").css("background-color", "blue")
            .end()
            .slice(-5).css("background-color", "red");
    }
    

    http://api.jquery.com/slice

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

Sidebar

Related Questions

I'm quite new to javascript but have undertaken a task to get better aquainted
I have a problem with Javascript that keeps bugging me for quite a while
I searched (trust me!) but for some reason, haven't quite found the answer I'm
I know this is so basic, but for some reason it's just not doing
I have a JavaScript function which is quite long and performs a number of
I am quite new to javascript, but not to programing in general. What I
I want to spend the summer getting into web development. I have some basic
I'm a .Net developer but I have a situation where I can't guarantee that
I am quite new to JavaScript and I am looking for a basic API
Heads up: I am quite new to Javascript and have so far only written

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.