9

Can we write multiple css style in single line in JQuery

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

Does we can write this to single line like below

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

3 Answers 3

13

You can pass an object with the key as the property and the value as what you may expect.

$('.ui-dialog').css({
  left: 475,
  top: 215
});
4

Yes you can. The jQuery .css() method also accepts a map. Check their documentation for more examples.

$('.ui-dialog').css({
    'left' : '475px', 
    'top' : '215px'
});
2

You can also chain css calls together:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.