jquery order <li> in the beginning of the list if it is tagged with special class
<p>I have this beautiful jquery script that takes list of <code>li</code>s and groups them under <code>ul</code> 4 <code>li</code> each.</p>

<p>But some of the <code>li</code>s have a special class: <code>&lt;li class="prefslidefeatured"&gt;</code></p>

<p>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.</p>

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

<p>I also made jsfiddle for quick dirty test :) <a href="http://jsfiddle.net/sandrodz/5at2G/" rel="nofollow">http://jsfiddle.net/sandrodz/5at2G/</a></p>

<pre><code>//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 = $("&lt;div /&gt;");
    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 = $("&lt;div /&gt;");
    current_li_div.append($("&lt;ul /&gt;"));

    // 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 = $("&lt;div /&gt;");
            current_li_div.append($("&lt;ul /&gt;"));
        }

    });

    // 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
    });

});
</code></pre>
