4

Is there any reason that this CSS shouldn't work?

$('.selector').css(
            'background-color', '#74d04c',
            '-webkit-box-shadow','inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            '-moz-box-shadow','inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            'box-shadow','inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            'border','1px solid #4c8932'
            );

The only one that is showing is the background-color.

1
  • Which browsers have you tested this with? (As CSS3 does not work in every browser.) Commented Jan 10, 2011 at 18:45

6 Answers 6

11

.css takes either a property name and value, or a map. You can do this:

$('.selector').css('color','blue');

...or this:

$('.selector').css({'color':'blue', 'left':'100px'});

The problem is that you're mixing the two approaches. Instead, try it like this:

$('.selector').css({
  'background-color':'#74d04c',
  '-webkit-box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
  etc...
});
Sign up to request clarification or add additional context in comments.

Comments

6

I think you're supposed to add the different rules using javascript object notation, not as a huge array.

Update: Yep - it accepts either two string parameters (key, value), or a map of key-value pairs. Source: http://api.jquery.com/css/

Comments

1

If you're applying multiple rules, you have to pass the css function a JS object. More details.

$("selector").css({"background-color": "red", "color": blue});

Comments

1

This should work:

$('.selector').css({
    'background-color' : '#74d04c',
        '-webkit-box-shadow' : 'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
        '-moz-box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
        'box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
        'border':'1px solid #4c8932'
    });

Demo

Comments

1

Fix your syntax.

$('.selector').css({'background-color' : '#74d04c',             
                    '-webkit-box-shadow' : 'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',             
                    '-moz-box-shadow' : 'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',             
                    'box-shadow' : 'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',             
                    'border' : '1px solid #4c8932'}); 

Comments

0

If you want to set multiple CSS attrs like that, you need to use a map:

$('.selector').css({
            'background-color':'#74d04c',
            '-webkit-box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            '-moz-box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            'box-shadow':'inset 0px 1px 0px 0px #dbf383, inset 0px -1px 1px #58c43a',
            'border':'1px solid #4c8932'
            });

Comments

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.