save jquery ui slider value in cookie

save jquery ui slider value in cookie

Using the UI Slider to set background opacity in a theme switcher. I can see in the consolde the cookie value updates but doesn't save when i refresh the page.

  1. $(function() {

        if ($.cookie('headOp')==null){
            $.cookie('headOp',0.5);
        }
       
        $( "#op-slider-header" ).slider({
            max: 1,
            min: 0,
            value: 0.5,
            step:0.1,
            slide: function(e,ui) {

              $.cookie('headOp',ui.value);
             $('#headerOpVal').html(ui.value);
            }
        });
       
         
        $( "#op-slider-header" ).on( "slidestop", function( event, ui ) {
            var val = $('#headerOpVal').html(ui.value);
            $('.row.header .bg').css('opacity', ui.value);
            $.cookie("headOp", ui.value, { expires: 7});
        });
    });