Here's my code:
var frameWidth = 400;
var imageWidth = $('#inner-image').css('width');
var numberOfFrames = imageWidth/frameWidth;
How do I make "numberOfFrames" display as a quotient? I.E. process "frameWidth" and "imageWidth" as numbers, rather than objects?
Let me know if I need to explain myself more clearly. Thanks!
Dividing. The division operator ( / ) divides numbers.
The division assignment operator ( /= ) divides a variable by the value of the right operand and assigns the result to the variable.
HTML. Division The division operator (/) divides two or more numbers.
.css('width') is likely returning the value with px. You can use parseInt() to get only the number.
var frameWidth = 400;
var imageWidth = parseInt( $('#inner-image').css('width'), 10);
var numberOfFrames = imageWidth/frameWidth;
The second argument 10 specifies the base that parseInt() should use.
You can also use the width()(docs) method to get the result without the px.
var frameWidth = 400;
var imageWidth = +$('#inner-image').width();
var numberOfFrames = imageWidth/frameWidth;
Here I used the unary + operator to make it a Number instead of a String.
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