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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:27+00:00 2026-06-17T16:37:27+00:00

I’m trying to learn to structure my code better, and have started using the

  • 0

I’m trying to learn to structure my code better, and have started using the pattern below after following a few tutorials.

I’ve had a fair amount of success building a number of common UI widgets this way, though I’ve hit my first wall, the .each() loops below do not seem to actually be looping through each item but are applying the desired action as if it was acting on all of the items in one iteration.

I read something about $.each and objects, though I’m not sure about $.each, or even whether it is teh direction I should be going.

jQuery(document).ready(function($) {

var tabs = {

    trig : $('nav.tab-triggers'),
    content : $('section.tabs-content'),

    init : function() {
        tabs.address([tabs.trig]);
        tabs.address([tabs.content]);
    },

    address : function(item) {
        //for every instance of the item

        $(item).each(function() {
            var i = 1;
            $(this).addClass('tabs-' + i);

            // for ever child element in this instance of the item
            $(this).children().each(function() {
                var count = 1;
                if ( $(this).parent().is('nav') ) {
                    $(this).attr('href', '#tab-' + count);
               } else {
                    $(this).attr('id', 'tab-' + count);
               }

                count++;

            });

            i++;
        });
    },

    display : function () {
        //show hide stuff here.
    }


}

tabs.init();

});
  • 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-17T16:37:28+00:00Added an answer on June 17, 2026 at 4:37 pm

    So after much trial and error I’ve finally got it working.

    basically, as I understand it, I’m trying to iterate over a nested objet and so the .each needs to be replaced with $.each method which works slightly differently.

        address : function(obj) {
            // for each obj
            $.each(obj, function(index,value) {
                //for each instance of the trigger / content item in the obj
                 $.each(obj[index], function(index2,value2) {
                    //add an incrementing class for each matched element
                    $(value2).addClass('tabs-' + index2);
                    // get the children of each matched element
                    var kids = $(value2).children();
                    // loop through each of the children
                    $.each(kids, function(index3, value3) {
                        // if its parent is a nav element
                        if ( $(value3).parent().is('nav') ) {
                            // add href
                            $(value3).attr('href', '#tab-' + index3);
                        } else {
                            // add matching ids
                            $(value3).attr('id', 'tab-' + index3);
                        }
    
    
                    });  // end loop through children elements
                 }); // end loop through parent elements
            }); // iteration of passed obj
        }, // end address method
    

    Thats the new method – that works. Is there a better way to do this ?

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.