How do I put a variable in a string in JavaScript?
Example:
$('#contactForm').animate({"marginLeft": "+=680px"}, "slow");
I would like to use in a variable instead of 680px
, is there a way to do this?
How do I put a variable in a string in JavaScript?
Example:
$('#contactForm').animate({"marginLeft": "+=680px"}, "slow");
I would like to use in a variable instead of 680px
, is there a way to do this?
As with most languages that don't have sigals, you can't perform interpolation, you have to concatenate multiple strings.
You can use the
+
operator to concatenate your value in a variable to the"+="
string: