Lan Mai
Lan Mai

Reputation: 375

CSS Margin Minus Equal in jQuery

Is there a way in jQuery that we can do something like:

$('#element').css('margin-left',-=10);

The purpose is for propeties like Left, Right, Width, Height, Margins, Paddings,... Thank you!

Upvotes: 1

Views: 414

Answers (2)

Serg Chernata
Serg Chernata

Reputation: 12400

Yes, this is possible. The syntax is just a little bit different.

$('div').css('margin-left',"-=10px");
div{margin: 40px; background: red; height: 20px; width: 20px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<div></div>

Upvotes: 2

PlantTheIdea
PlantTheIdea

Reputation: 16369

You're trying a shorthand (that I don't think exists) for a pretty straightforward application of an explicit getter:

const $element = $('#element');

$element.css('margin-left', $element.css('margin-left') - 10);

Upvotes: 0

Related Questions