In PHP you can use this to keep a number between 2 values, minimum and maximum:
$n = min(max($n, 1), 20);
so if $n is larger than 20 it will take the value of 20.
If it’s smaller than 1 it will take the value of 1. Otherwise it will not change
How can I do this in javascript / jQuery ?
It’s pretty much the same in JavaScript, only that
minandmaxare members of theMathobject: