jquerycssjquery-hoverjquery-attributes

jQuery change images on links hover


I have a problem with a code below. Somehow I'm not able to change image background using jQuery script.

HTML code looks like:

jQuery code looks like:

$(document).ready(function(){
        $('.hoverlink').hover(function(){$('.group-image').css('background', $(this).attr('data-img'))});
});

data-image tag contains correct URL to an image for related links, but when I hover any of those links it doesn't add background CSS to group-image div. JSFillde of an examle

Any clue where I have made an error?

Thanks


Solution

  • $('.hoverlink').hover(function(){
        $('.group-image').css('background-image', 'url('+$(this).attr('data-img')+')')
    });
    

    This works!! Updated fiddle