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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:10:44+00:00 2026-06-06T17:10:44+00:00

How to find last class on the element without knowing exact number of classes?

  • 0

How to find last class on the element without knowing exact number of classes?

Our element:

 <div class="class-1 class-2 some-other-class"></div>

Normal approach with split will not work here, as we do not know the number of classes. Can we check the length of the .split(' ') ?

var i = $('div').prop('class');
var j = i.split(' ')[x];

Any suggestions much appreciated.

  • 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-06T17:10:46+00:00Added an answer on June 6, 2026 at 5:10 pm

    The simplest solution is to use pop, which accesses the last element in the array.

    var lastClass = $('div').attr('class').split(' ').pop();
    

    Note that pop also removes the element from the array, but since you aren’t doing anything else with it, that’s not a problem.

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

Sidebar

Related Questions

Im having some trouble removing part of a cloned element: console.log($(this).closest('tr').clone().find('td:last')); //this is the
I need to be able to find the last occurrance of a number within
I want to retrieve the class name of the last child element (class last
How can I find the last day of the month in C#? For example,
When I want to find the last used cell value, I use: Dim LastRow
I would like to find the last line matching a certain pattern, in python.
I am looking to find the last positional parameter. I know to find the
I am writing a shell script in which I have to find the last
i have a string %/O^/O%/O . I want to find the last / to
I have an unordered list, and am using jquery to find the last ul

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.