parseInt() is pretty sweet.
var text = $('#foo').text(); var number = parseInt(text, 10); alert(number);
parseInt() will process any string as a number and stop when it reaches a non-numeric character. In this case the the
280ms. After have found the digits
0, evaluates those digits as base 10 (that second argument) and returns the number value
280. Note this is an actual number and not a string.
@Alex Wayne's comment.
Just filter out the non numeric characters first.
parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);