How to use a different image for each jQuery UI slider handle

I use the jQuery UI slider, which has two handles (aka range slider). I know the style of the first descriptor :

.ui-slider-horizontal .ui-slider-handle {background: white url(https://stackoverflow.com/content/img/so/vote-arrow-down.png) no-repeat scroll 50% 50%;}

But how do I style the second descriptor differently?

Using Firebug I see that Jquery does not uniquely identify each descriptor:

<div id="hourlyRateSlider" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
 <div class="ui-slider-range ui-widget-header" style="left: 26%; width: 46%;"/>
 <a class="ui-slider-handle ui-state-default ui-corner-all" href="#" style="left: 26%;"/>
 <a class="ui-slider-handle ui-state-default ui-corner-all" href="#" style="left: 72%;"/>
</div>

So, I assume that I need to use either a CSS child selector, which may be cross-browser issues. Or can I use some jQuery tricks to add a CSS class to the second descriptor? Has anyone done this in a neat way before?

+5
source share
2 answers
$(window).load(function(){
    handle = $('#slider A.ui-slider-handle');        
    handle.eq(0).addClass('first-handle');        
    handle.eq(1).addClass('second-handle');
});
+12

CSS

#hourlyRateSlider a:last-child {}
0

All Articles