change one image at a time using jquery -


hi have got 5 labels of product , want change background-image of label clicked, instance if product 1 clicked background-image should change background-image:url('/images/product1-selected'), if product 2 selected background image product 2 should background-image:url('/images/product2-selected'), in case product 1 image should go previous image product 2 selected. want show 1 image selected @ time , instance if product 2 selected other products should go default image defined in styles of each label, vice vera

<label for="1" style="background-image:url('/images/product1');width:50px;height:49px;">product 1</label> <label for="2" style="background-image:url('/images/product2');width:50px;height:49px;">product 2</label> <label for="3" style="background-image:url('/images/product3');width:50px;height:49px;">product 3</label> <label for="4" style="background-image:url('/images/product4');width:50px;height:49px;">product 4</label> <label for="5" style="background-image:url('/images/product5');width:50px;height:49px;">product 5</label> 

any ideas on how using jquery. appreciated thanks

something using jquery data function

   $(function        $('label').click(function () {            if($(this).data('oldimg')) return false;             $('label').filter(function(){return $(this).data('oldimg')}).each(function () {               $(this).css('background-image', $(this).data('oldimg')).removedata('oldimg');            })            $(this)               .data('oldimg', $(this).css('background-image'))               .css('background-image', $(this).css('background-image').replace(/(\.\w{3})/, '-selected$1'));         })     }) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -