Is this the correct method of using?
It's fine if your descMargin is meant to be in pixels (not % or em or rem or ...), and if it's actually a number (I'm guessing from your code snippet that it is).
If you just use a number, jQuery converts it to a string and appends px for you. From the documentation:
When a number is passed as the value, jQuery will convert it to a string and add px to the end of that string. If the property requires units other than px, convert the value to a string and add the appropriate units before calling the method.
What you don't want to do is pass it a string that's all digits. So don't give it "26", for instance; but 26 is fine.
So:
// This:
$("p").css("margin", 20);
// Does the same thing as this:
$("p").css("margin", "20px");
// But DON'T do this:
$("p").css("margin", "20"); // <== Wrong
Live Example:
var div = $("div");
test("50px");
setTimeout(test.bind(null, 40), 300);
setTimeout(test.bind(null, "30"), 600);
function test(value) {
var rawValue = String(value).replace(/\D/g, '');
var rawPadding;
var result;
div.css("padding-left", value);
var result = div.css("padding-left").replace(/\D/g, '') == rawValue ? "worked" : "failed";
$("<p>")
.html("Result for " + JSON.stringify(value) + ": " + result)
.appendTo(document.body);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>text</div>
pxto the variable