var x = e.pageX;
var myX = $(this).html();
var difference = myX - x;
var ex = myX + difference;
Everything workes until the last row. It doesn´t make an addition, it puts together the variables into one string. If myX is 10 and difference is 20 it will be 1020 when I want it to be 30.
How do I solve this?
You can force the variables to be integer using something like this :
var ex = parseInt(myX, 10) + parseInt(difference, 10);
This happen because your variables are considered as strings, and using the + operator on strings concatenates then togheter instead of adding their numeric values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With