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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:38:22+00:00 2026-06-08T08:38:22+00:00

I have this beautiful jquery script that takes list of li s and groups

  • 0

I have this beautiful jquery script that takes list of lis and groups them under ul 4 li each.

But some of the lis have a special class: <li class="prefslidefeatured">

I want this special li to stay at the top of the list thus in the first ul as first li. There can be several lis tagged featured so I want all of them to stay at the beginning of the list thus first ul.

Is this script I have easily modifiable to accommodate this new feature? Any ideas how to achieve this?

I also made jsfiddle for quick dirty test 🙂 http://jsfiddle.net/sandrodz/5at2G/

//This is for footer slider, it rewrites 1 ul into several uls that contain 4 li max.
$(document).ready(function(){

    // get the container, useful for later too...
    var container = $(".prefooterslides");

    // get all available UL and LI elements...
    var li_elements = container.find("LI").clone();

    // remove the current content so that we can rebuild it for the slider...
    container.find("UL").remove();

    // build the slider container...
    var slide_container = $("<div />");
    slide_container.addClass("slides_container");

    // tricky part: looping through the LI's and building each of the slides...
    // first create some helpful variables...
    var li_elements_per_slide = 4;
    var li_counter = 0;
    // create the first slide, with a UL to hold the LI's...
    var current_li_div = $("<div />");
    current_li_div.append($("<ul />"));

    // loop through the LI's...
    li_elements.each(function(index, element){

        li_counter++;
        var current_li = $(element).clone();
        current_li_div.find("UL").append(current_li);

        if (li_counter % li_elements_per_slide == 0)
        {
            // we've hit 4 in this list, so add the slide and make
            // a new one, using same code as before...
            container.append(current_li_div);
            current_li_div = $("<div />");
            current_li_div.append($("<ul />"));
        }

    });

    // we might have an uneven number of LI's, so we need to check for this...
    if (li_counter % li_elements_per_slide != 0)
        container.append(current_li_div);

    // all that's left to do is to initialise the slider script...
    $("#prefooterindex").slides({
        container: 'prefooterslides',
        generatePagination: false
    });

});
  • 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-08T08:38:23+00:00Added an answer on June 8, 2026 at 8:38 am

    Try this:

    Change:

    var li_elements = container.find("LI").clone();
    

    to:

    var li_elements = container.find("LI.prefslidefeatured").clone();
    li_elements = li_elements.add(container.find('LI:not(.prefslidefeatured)').clone());
    

    It gets all of the featured lis first, then adds all of the non-featured lis to the end of the array. The .each() further down now iterates over the featured items first, meaning they get added to the top-most uls.

    Fiddle: http://jsfiddle.net/5at2G/1/

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

Sidebar

Related Questions

I have currently implemented this image slider http://www.dreamcss.com/2009/04/create-beautiful-jquery-sliders.html on a site but for some
I have this iPhone like checkbox script, which makes beautiful checkboxes. The code is
I have this xml <products> <product> <name>Demo</name> </product> <product> <name>Black Beauty III</name> <description>Beautiful les
Let's say I have an array like this: $array = array (this,is,me,and,I,am,an,array,hello,beautiful,world); How can
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I am using this example of quicksand jQuery. Making a Beautiful HTML5 Portfolio Now,
i have built a beautiful website that works very fast in all of the
I saw this beautiful script to add thousands separator to js numbers: function thousandSeparator(n,
I have jQuery slider code that I want to populate via a JSON url.
I have the following little jQuery hack to make any HTML that shows up

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.