Skip to content Skip to sidebar Skip to footer

Html Tag Attribute "data-setbg" Is Not Working In React Project

I'm converting a HTML website template into a React project, in that template there is an attribute called data-setbg, but there is no standard html attribute provided, I wonder wh

Solution 1:

it turns out the writer is using JavaScript to do a short cut and easy way for setting up the element background as image, I found this .js code within the templates:

    $('.set-bg').each(function() {
        var bg = $(this).data('setbg');
        $(this).css('background-image', 'url(' + bg + ')');
    });

Solution 2:

This one works Move all code into the $(window).on('load',function(){...})

CSS background-image renders as url('undefined'); even though I defined it. (JSX)


Post a Comment for "Html Tag Attribute "data-setbg" Is Not Working In React Project"