html - How to increase a css value, rather than concatenate it? -
i'm using line:
$(this).css("z-index", z + 10);
the set z-index value 1200.
edit: variable z = $(this).css("z-index");
when debugging in developer console noticed z-index value '120010' rather expected '1210'.
how can change above line increase value 10, rather concatenating value end.
(also using word right? i'm not 100% sure)
you need use parseint()
function on z
variable. should work:
z = parseint($(this).css("z-index")); $(this).css("z-index", z + 10);
one thing careful though, z-index
can have value not number, example auto
if run parseint()
on element that's z-index auto, break.
in order combat this, recommend using zindex()
(part of jquery ui) instead of css()
so:
z = $(this).zindex(); $(this).css("z-index", z + 10);
this of course means have use jqueryui, if using it, i'd recommend approach.
edit: looks zindex()
has been removed jquery ui, stick first suggestion. http://jqueryui.com/upgrade-guide/1.12/#removed-zindex
Comments
Post a Comment