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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:45:30+00:00 2026-05-25T18:45:30+00:00

Okay, this may be a bit basic. The HTML is : <div class=parents-of-all> <p>

  • 0

Okay, this may be a bit basic. The HTML is :

<div class="parents-of-all">
<p>
    <a>
        <span class="thechild">Something</span>
    </a>
</p>

The jquery is

$('.parents-of-all').click(function(){
    alert($(this).find('span').attr('class'));
});

But somehow it doesn’t work. Test it here :

http://jsfiddle.net/3zn7e/1/

My question is how can I traverse to the span? My usual way is

$(this).children().children().children().attr('class');

I’m sure there are shorter ways than this and using find() is one of them, but I can’t seem to make it work.

Many thanks!

EDIT : DUH! Apparently I forgot the . for the parents-of-all DOM selector. Sometimes the simplest error is right there in your face.

But again, is there any difference between using find() and multiple children() ? I find using multiple children() ensures more accurate traversing since we can add elements selector if we want, but any other major difference?

  • 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-25T18:45:30+00:00Added an answer on May 25, 2026 at 6:45 pm

    You were missing the dot in your class selector:

    $('.parents-of-all').click(function(){
        alert($(this).find('span').attr('class'));
    });
    

    http://jsfiddle.net/BoltClock/3zn7e/2

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

Sidebar

Related Questions

Okay this one may be a bit out from left field, but I'm going
Okay this may be a simple question but I have yet to come with
Okay, this may be a dumb question, but I've not been able to find
Okay, This may be really simple or it may not even be possible, or
Okay, so this one may be difficult but I will do my best to
Okay this is not a question of how to get all uniques or How
Okay so the title may be a bit misleading. What I am trying to
Okay, this may seem silly, but on an ASP.NET .ascx control, I'm trying to
This may be a basic question... However I've just been picking a solution without
Okay I know this may sound like any other issues regarding the ListView and

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.