-3
$('.rightArrow').click(function(){
            $('body').css({
                'background':
                'linear-gradient(rgba(0, 0, 0, 0.30),rgba(0, 0, 0, 0.30)),
                 url("../img/change1.png") no-repeat center center fixed'
            });
        });

I did it with css but I got error in setting it using jquery. Is this even possible? or I should split them out, like only changing the background-image? since the overlay will be there for all images.

Elton Jamie
  • 586
  • 6
  • 17
  • You need to use [.css](http://api.jquery.com/css/) method of jquery in order to change the properties of the background. – kidA Mar 05 '15 at 09:57
  • @kidA updated my code but still got errors. – Elton Jamie Mar 05 '15 at 09:59
  • If your code is as it is written here there's the multi-line string problem: http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript which could result in a syntax error. Or is that just SO formatting? Other than this it looks okay – blgt Mar 05 '15 at 10:02
  • You should set background value in single line – Satpal Mar 05 '15 at 10:04

1 Answers1

1

You can't have a new line in the middle of a JavaScript string without escaping it. The new line character is the illegal token.

It should be:

'linear-gradient(rgba(0, 0, 0, 0.30),rgba(0, 0, 0, 0.30)), url("../img/change1.png") no-repeat center center fixed'

or

'linear-gradient(rgba(0, 0, 0, 0.30),rgba(0, 0, 0, 0.30)),\
url("../img/change1.png") no-repeat center center fixed'
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335