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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:08:06+00:00 2026-05-26T01:08:06+00:00

I’m a little confused. Basically, I’ve got 16 span elements on my page which

  • 0

I’m a little confused. Basically, I’ve got 16 span elements on my page which are displaying brands. I want to show only 4 brands at a time, and then set an interval to show the next 4 brands until I reach the end, at which point I’ll reset a counter and start from the beginning again. Here is what I was thinking:

  1. Display all brand span elements
  2. Put all of the brand elements into an array
  3. Count first 4 items (brands) and give them the class of visible
  4. After 5 seconds, hide all elements with class of visible
  5. Display the next 4 items in the array
  6. When the end of the array is reached, reset the counter and start again

Some general advice or help with jquery arrays would be appreciated. I’m looking for the most dynamic and simple solution possible.

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-05-26T01:08:07+00:00Added an answer on May 26, 2026 at 1:08 am

    Here, it’s a bit hackish though…

    var elems = $( 'span' ).hide().get();
    
    (function loop () {
        var i = 0, pointer;
    
        pointer = $( elems ).filter( ':visible:last' )[0] || $( elems ).last()[0];
    
        $( elems ).hide();
    
        while ( i < 4 ) {
            pointer = $( pointer ).next()[0] || $( elems ).first()[0];
            $( pointer ).show();
            i += 1;
        }
    
        setTimeout( loop, 5000 );
    })();
    

    Live demo: http://jsfiddle.net/hBrt6/

    If you require an explanation of the code, just let me know…


    A few explanations:

    .get() returns an array of the DOM elements inside the jQuery object.

    So

    $( 'div' ).get()
    

    gives you an array of all the DIV elements on the page.

    Using the property accessor operator [i] will give you the i-th DOM element from the jQuery object.

    So

    $( 'div' )[4]
    

    returns the fifth DIV element on the page.

    It is important to understand that you cannot invoke jQuery objects on DOM elements itself (or arrays of DOM elements).

    So this

    $( 'div' )[4].hide();
    

    throws an error. DOM elements don’t have a hide method.

    If you want to target a specific element inside a jQuery object and while still retaining a jQuery object, use .eq().

    This

    $( 'div' ).eq( 4 ).hide();
    

    works just fine.

    Now that you understand this difference, let me explain why I use get() and [i] in my code: The thing is, I don’t like to store jQuery objects inside variables. Instead I prefer to work with DOM elements and arrays of DOM elements directly.

    When I need to invoke a jQuery method on some element or array of elements, I just wrap it inside the $() function first.

    So this

    $( elems ).hide();
    

    works just fine.

    And when the jQuery method has done the job, I just append .get() or [0] to “unwrap” the jQuery object = to get my element(s) back.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.