Please tell me why I can’t set the scale for the div?
var a = 0.1;
var b = 0.1;
var scale = a+b;
$(".item").css('scale', scale)
.item {
width: 100px;
height: 100px;
background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="item"></div>
2
Answers
As per the documentation :
Thus, the parameter has to be a string, not a number :
Besides you need to pass as string like
.css("scale", `${scale}`)
or.css("scale", scale.toString())
(as already suggested by @Tom),..you don’t need jQuery for that task, just plain JS and CSS Var:
MDN: Using CSS custom properties
MDN: CSS var()