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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:14:22+00:00 2026-06-11T22:14:22+00:00

All, I’ve done my very best to figure this out, though possible examples I’ve

  • 0

All, I’ve done my very best to figure this out, though possible examples I’ve found are far more complicated and it seems as though I’m the only one out there having this problem, so I’m coming to you for help, or perhaps just an explanation.

In the code below, I would expect to see three alerts in a row, tab-1, tab-2, and tab-3, but instead I see three alerts of tab-1. Why is this and what might be the solution to get the desired effect?

Thanks for your time and assistance.

The HTML

<div id="tab-1">
    <span class="test"></span>
</div>
<div id="tab-2">
    <span class="test"></span>
</div>
<div id="tab-3">
    <span class="test"></span>
</div>

The jQuery

$('.test').each(function() {
    alert($('.test').parent().attr("id"));
});

  • 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-11T22:14:23+00:00Added an answer on June 11, 2026 at 10:14 pm

    While your code is close, it’s not quite right. You should be using:

    $('.test').each(function() {
        alert($(this).parent().attr("id"));
    });
    

    Updated JS Fiddle demo.

    The problem you’re experiencing is that you’re reselecting the array on each iteration of each(), and jQuery will simply return the attributes of the first element of the array that’s returned.

    References:

    • each().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All the examples of use and tutorials I have found on beginBackgroundTaskWithExpirationHandler: show how
All the info I've found on the internet about this says to use something
All my files can be found on GitHub: https://github.com/Integralist/Passage (just in case you need
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
All, I am trying to create a table to receive user inputs (UGC). This
All, I'm using wordpress with this and for some reason the eventDrop stopped working.
All, In my Lex file we recognize some operators as Tokens some of this
All! I found strange code in LinkedBlockingQueue: private E dequeue() { // assert takeLock.isHeldByCurrentThread();

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.