Can we write multiple CSS styles in one line in jQuery

Is it possible to write multiple CSS styles on the same line in jQuery

$('.ui-dialog').css("left","475px"); $('.ui-dialog').css("top","215px"); 

Is it possible to write this in one line, as shown below

  $('.ui-dialog').css("'left','475px'","'top','215px'"); // Test 
+8
jquery css
source share
3 answers

You can pass an object with a key as a property and value, as you can expect.

 $('.ui-dialog').css({ left: 475, top: 215 }); 
+13
source share

Yes, you can. The jQuery.css () method also accepts a map. See the documentation for more details.

 $('.ui-dialog').css({ 'left' : '475px', 'top' : '215px' }); 
+3
source share

You can also combine css calls:

 $(".ui-dialog").css("left", "475px").css("top", "215px"); 
+2
source share

All Articles