To set margin CSS properties with jQuery, we can call the css
method to change the margin CSS properties.
For instance, if we have the following HTML:
<div>
hello
</div>
Then we write:
$('div').css('margin-left', '100px');
to select the div with $('div')
.
Then we call the css
method on the returned div jQuery object with the property key and value we want to set respectively.
Therefore, we set margin-left
to 100px
.
The unit must be included.
Now we should see a 100px left margin added to the div.