Review on my multiple JQuery Slider on a page I have successfully placed multiple jquery ui slider on a page and its transalation text too. you can check it live on:
http://outsourcingnepal.com/projects/jQuery%20slider/

I have my jquery code as :

var arrLabel1 = new Array('Not Good', 'OK', 'Average', 'Above Average', 'Excellent', 'Outstanding');
$(function() {
    $( ".slider_control" ).slider({
        value:0,
        min: 0,
        max: 5,
        step: 1,
        slide: function( event, ui ) {
            $( "#slider_" + $(this).attr('rel') ).val( ui.value );
            $( "#label_" + $(this).attr('rel') ).text( arrLabel1[ ui.value ] );
        }
    }).each(function(index){
        $( "#slider_" + (index + 1) ).val( $( this ).slider( "value" ) );
        $( "#label_" + (index + 1) ).text( arrLabel1[ $(this).slider( "value" ) ] );
    });
});


Now i would like to optimize it so that i can be independent of rel attribute.

MY HTML:

&lt;ul class="slider-container"&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Overall: &lt;span id="label_1"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_1" /&gt; 
        &lt;div class="slider_control" rel="1"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Cleanliness: &lt;span id="label_2"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_2" /&gt; 
        &lt;div class="slider_control" rel="2"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Facilities: &lt;span id="label_3"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_3" /&gt; 
        &lt;div class="slider_control" rel="3"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Location: &lt;span id="label_4"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_4" /&gt; 
        &lt;div class="slider_control" rel="4"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Quality of Service: &lt;span id="label_5"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_5" /&gt; 
        &lt;div class="slider_control" rel="5"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Room: &lt;span id="label_6"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_6" /&gt; 
        &lt;div class="slider_control" rel="6"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
    &lt;li class="ui_slider"&gt; 
        &lt;div class="title"&gt;Value of Money: &lt;span id="label_7"&gt;&lt;/span&gt;&lt;/div&gt; 
        &lt;input type="hidden" name="overall_review" id="slider_7" /&gt; 
        &lt;div class="slider_control" rel="7"&gt;&lt;/div&gt; 
    &lt;/li&gt; 
&lt;/ul&gt;
In my option your code has two problems:


You unnecessarily fill your HTML with empty elements which you could just create in your script. Changing that would remove the necessity for the rel attribute.
more importantly (even if there are people that may disagree), you have unnecessarily made your form dependent on JavaScript. It would be much better to have select elements in your HTML, which you can replace with sliders. That way even users without JavaScript can use your form unrestricted.


I've written an example how I would do it:

$(".ui_slider select").each(function() {
    var select = $(this); // Cache a refernce to the current select
    var sliderDiv = $("&lt;div&gt;&lt;/div&gt;"); // create a div for the slider
    var displayLabel = $("&lt;span&gt;&lt;/span&gt;"); // create a span to display current selection

    if (select[0].selectedIndex &lt; 0) // Make sure that an item is selected
        select[0].selectedIndex = 0;

    select
        .hide() // hide the select
        .before( // Insert display label before the select
            displayLabel
               .text(select.find("option:selected").text()) // and set it's default text
        )
        .after( 
           sliderDiv // Insert the silder div after the select
               .data("select", select) // store a reference to the select
               .data("label", displayLabel) // store a reference to the display label
               .slider({
                    max: select.find("option").length - 1, // set to number of items in select
                    slide: function(event, ui) {
                        var select = $(this).data("select"); 
                        select[0].selectedIndex = ui.value; // update the select
                        $(this).data("label").text( // Update the display label
                            select.find("option:selected").text()
                        );
                    }
               })
        );
});


HTML (repeat as needed):

&lt;div class="ui_slider"&gt;
    &lt;label for="overall"&gt;Overall: &lt;/label&gt;
    &lt;select name="overall" id="overall"&gt;
        &lt;option value="0"&gt;Not Good&lt;/option&gt;
        &lt;option value="1"&gt;OK&lt;/option&gt;
        &lt;option value="2"&gt;Average&lt;/option&gt;
        &lt;option value="3"&gt;Above Average&lt;/option&gt;
        &lt;option value="4"&gt;Excellent&lt;/option&gt;
        &lt;option value="5"&gt;Outstanding&lt;/option&gt;
    &lt;/select&gt;
&lt;/div&gt;


Working sample: http://jsfiddle.net/YfqCx/2/