jQuery Style How to - Change multiple css properties








Question

We would like to know how to change multiple css properties.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--  www .  j ava2 s. c o  m-->
    var myvar = 120;
    $('#mydiv').css({
        width: myvar,
        marginLeft: myvar
    });
});
</script>
</head>
<body>
  <div id="mydiv">test</div>
</body>
</html>

The code above is rendered as follows: