Change Background Image Url Using Jquey

<script type="text/javascript">
    $('li.swatch').each( function() {
    var thumbnail_url = $(this).find('.thumbnail').css("background-image");  
    var src = thumbnail_url.split('thumbnail');
    var split_url = src[0].split('"');
    var split_url_link = split_url[1];
    var split_img = src[1].split('"');
    var split_img_link = split_img[0];
    var preview ="preview";
    var img_url = split_url_link+preview+split_img_link;
    $(this).find('.thumbnail').css("background-image", 'url('+ img_url+ ')')
    });
 
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *