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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:11:51+00:00 2026-06-07T22:11:51+00:00

so basically here is my script: http://jsfiddle.net/JJFap/42/ Code – jQuery(document).ready(function() { var rel =

  • 0

so basically here is my script:

http://jsfiddle.net/JJFap/42/

Code –

jQuery(document).ready(function() {
    var rel = new Array();
    var count = 0;
    jQuery(".setting").each(function() {
        rel[count] = [];
        if(jQuery("span").attr("rel")) {
            rel[count].push(jQuery("span").attr("rel"));
        }  
        console.log(count);
        count++;
    });               
    jQuery("body").text(rel);
    console.log(rel);
});​

and

<div class="setting">
    <span rel="Variable">Variable</span>
    <span rel="Item">Item</span>
    <span rel="Something">Something</span>
</div>
<div>
    <span rel="Smth">Smth</span>
    <span>Sec</span>
</div>
<div class="setting">
    <span>Second</span>
    <span rel="first">First</span>
    <span rel="Third">Third</span>
</div>

​my question, is why does it display Variable, variable?

I would like it to display Variable, First, but I’m not able to do.

Basically what I would like to achieve is create new array, in which insert each div.setting span elements with rel attribute array.

So basically in this example it should output –

Array (

   Array[0] => "Variable","Item","Something";

   Array[1] => "first","Third";

)

Hope you understood what I meant 🙂

EDIT:

In my other example I tried to add jQuery(“span”).each(function() … inside first each function, but it outputted two full arrays of all span elements with rel. I can’t have different classes / ids for each div element, since all will have same class.

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

    In addition to what has been said, you can also get rid of the count and one push() when using jQuery.fn.map() as well as getting rid of the if when adding [rel] to the selector:

    jQuery(document).ready(function() {
        var rel = [];
        jQuery(".setting").each(function() {
            rel.push(jQuery(this).find('span[rel]').map(function() {
                return this.getAttribute('rel');
            }).get());
        });               
        jQuery("body").text(rel);
        console.log(rel);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the code: http://jsfiddle.net/hQnXm/7/ So basically i need when hover, it should animate
this is my implementation of a Jquery tooltip: <script type=text/javascript> $(document).ready(function(){ var tiempo_espera =
I've isolated the issue here: http://jsfiddle.net/ajkochanowicz/pEnMw/2/ Basically, I'm trying to add a feature in
I have created a fiddle here: http://jsfiddle.net/ozzy/paPRg/1/ Basically, I want to allow users to
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
I am stuck with a peculiar issue here. I have a script that basically
Basically, here's my problem. I'm calling someone else's FORTRAN functions from my C++ code,
Here is my code... basically it finds any page-NUMBER- within a variable and then
I'm having some issues with my code maybe you could help? Jquery: [updated] <script>
Here's the code I currently have. <!DOCTYPE html> <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8/>

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.