Ibanez
Ibanez

Reputation: 239

In jQuery how do I make multiple changes to css in a function?

Is there an easy way to make multiple changes to the css in jQuery without the extra lines of code? i.e. I have a function:

$(function() {
       $('h1[id=300]').click(function(){
       $('#box').css('background','orange');    
       $('#box').animate({
       "left" : "300px"
    }); 
  });           
}); 

Let's say I want to change the div box size. How would I add it within the changes that are already being applied to background color above?

Thanks

Upvotes: 1

Views: 81

Answers (2)

ialphan
ialphan

Reputation: 1261

You can do something like this:

        $("#box").css({
            background:'orange',
            left:'300'
        });

(where background and left are your styles)

Upvotes: 0

Dr.Molle
Dr.Molle

Reputation: 117324

Use a object where you define the styles as argument for css() , e.g.:

 $('#box').css({'background':'orange',
                'width':'200px',
                 height:'100px'}); 

Upvotes: 3

Related Questions