I have an element in javascript like follows:
<span>280ms</span>
I want to extract 280 from the span element. How can I do it? The content within the span element will be any number followed by ms.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
parseInt()is pretty sweet.HTML
JS
parseInt()will process any string as a number and stop when it reaches a non-numeric character. In this case themin280ms. After have found the digits2,8, and0, evaluates those digits as base 10 (that second argument) and returns the number value280. Note this is an actual number and not a string.Edit:
@Alex Wayne‘s comment.
Just filter out the non numeric characters first.