Reputation: 211
Trying to include a variable in my jquery:
var width = $(this).width();
$("#dynamic").html(".dropdown-bottom:before{left:'width'px;}");
How do I indicate that width is a variable in the .html?
Upvotes: 0
Views: 41
Reputation: 2290
Concatenate the strings together:
var width = $(this).width();
$("#dynamic").html(".dropdown-bottom:before{left:" + width + "px;}");
To subtract from your width, do so before the concatenation:
var width = $(this).width() - 20;
Since the documentation indicates that width() returns an integer, a simple subtraction should work here. This is of course presuming that this is actually referencing the correct thing.
Upvotes: 2
Reputation: 54790
$("#dynamic").html(".dropdown-bottom:before{left:" + width + "px;}");
Upvotes: 1
Reputation: 14565
by building up the string by using the variable:
$("#dynamic").html(".dropdown-bottom:before{left:" + width + "px;}");
Upvotes: 1