0

EXAMPLE

I'm trying to set the background of an element to a gradient, however it's not setting. It's adding style="" to markup and it works when I put the code directly into firebug (I'm using Firefox). Any idea why it's not working or how I can get it to work?

$('main > article').each(function (index) {
    var bg = $(this).css('background-color');
    var nextbg = $(this).next().css('background-color');
    if ($(this).next().length && nextbg != bg) {
        $(this).css('background', 'linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
        console.log('linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
        console.log('------------');
    }
});

1 Answer 1

5

Just remove the ";" at the end of your css

('main > article').each(function (index) {
    var bg = $(this).css('background-color');
    var nextbg = $(this).next().css('background-color');
    if ($(this).next().length && nextbg != bg) {
        $(this).css('background', 'linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%)');
        console.log('linear-gradient(to bottom, ' + bg + ' 0%, ' + nextbg + ' 100%);');
        console.log('------------');
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

facepalm - thanks! Knew it must be something daft! xD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.