jquery extract number from string code example

Example 1: jquery extract number from string

var id_of_div = "div_id_12";
var id_number = parseInt(id_of_div.replace(/[^0-9.]/g, ""));
console.log(id_number);//12

Example 2: javascript extract number from string

// Html: <span id="foo">280ms</span>

var text = $('#foo').text();
var number = parseInt(text, 10);
alert(number);

// parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);

Example 3: get number from string using jquery

You can get it like this:

var suffix = 'comment_like_123456'.match(/\d+/); // 123456

With respect to button:

$('.comment_like').click(function(){
  var suffix = this.id.match(/\d+/); // 123456
});

It works for me.