I have an element in javascript like follows:
280ms
I want to extract 280 from the span element. How can I do it?
Try this:
var num = document.getElementById('spanID').innerText.match(/\d+/)[0];
jQuery version:
var num = $('span').text().match(/\d+/)[0]; // or $('#spanID') to get to the span
If you want as numeric value (and not as string), use parseInt:
var num = parseInt($('span').text().match(/\d+/)[0], 10);