How to subtract margin from left using jquery
Hi everyone I need to subtract the mark css
using jquery I have this script please help me. I need to subtract 200 px
var mergin = $(this).css("left") - 200;
but not work
$(this).find('.circle').click(function(){
var margin = $(this).css("left");
$('.move_plane').animate({marginLeft:margin});
});
you only need this script
var margin = parseInt( $(this).css("left")) - 200;
enter code here
You need to convert your margin value to Integer
:
var margin = parseInt( $(this).css("left"), 10 );
Do you mean something like this?
$(this).css('left', "-=200");
or perhaps:
$(this).css('marginLeft', "-=200");
or just skip this step:
$('.move_plane').animate({'marginLeft': '-=200'});
Without a complete example of your code, including HTML and CSS, it's hard to tell what you really want to achieve.
Usually $(this).css("left")
will give you the value along with the scales like px, pt, em as you set. so infer the integer value from the value and -200 then add px and set it back.