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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:57:14+00:00 2026-06-15T08:57:14+00:00

We have: <div class=companylinks> <span class=current> <a class=welcome>Welcome!</a> </span> <span> <a class=ic_generalinfo>General Info</a> </span>

  • 0

We have:

<div class="companylinks">
   <span class="current">
      <a class="welcome">Welcome!</a>
   </span>
   <span>
      <a class="ic_generalinfo">General Info</a>
   </span>
</div>

I want to get the class of the <a> which is in the <span class="current"> (here is ‘welcome’)

var selected_tab = $('#companylinks span[class="current"]').closest('a').attr('class');
alert(selected_tab);

But I’m getting ‘undefined’, how I should ise closest() here?

I would appreciate any help.
Thanks

  • 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-15T08:57:15+00:00Added an answer on June 15, 2026 at 8:57 am

    .closest() goes up the parent chain, not down the parent chain.

    To specify multiple parents that all must be satisfied in a selector, you can just list them separately in the selector separated by spaces. In this case you can target the <a>tag inside of .current and then obtain its class like this:

    $(".current a").attr("class");
    

    Or, if you want to scope it only to inside of .companylinks, then you can use this;

    $(".companylinks .current a").attr("class");
    

    Note: You don’t need to use span[class=".current"]. You can just use .current.

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

Sidebar

Related Questions

I have a bunch of div's: <div class='option'> <span>here is a label for one
I have a div class named switch control which has a div class named
for example I have the following: I want to go through each div class
I want to display some div's in a wrap. The div have same class
I have many DIV with the same class name, let save wmplayer. I want
I have a class of div MyClass I want to hook up to two
I have div class called .stage which is a stage of a questionnaire <div
I have a div with class name: .sel-display-on. When clicked, I want to change
I have <div class='line'> <div class='chord_line'> <span class='chord_block'></span> <span class='chord_block'>E</span> <span class='chord_block'>B</span> <span class='chord_block'>C#m</span>
The esample is here: http://jsfiddle.net/SsPqS/ I have a div with class=record I add 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.