I have a button on my page with a class of comment_like and an ID like comment_like_123456 but the numbers at the end are variable; could be 1 to 1
comment_like
comment_like_123456
This would be the easiest way to grab number from a string using jquery.
$(function(){ $('.comment_like').click(function() { var element_id = $(this).attr('id'); var number = element_id.match(/\d+/); alert(number); }); });
Click Me To Get a number from string