Get the numerical part of the identifier
If you always have the ITEM prefix, you can
var numeric = this.id.replace('ITEM',''); and as @Felix mentions in the comments, you can convert it directly to a usable number (instead of just representing the string) using the + unary MDC docs operator instead
var numeric = +this.id.replace('ITEM',''); In addition, I changed $(this).attr('id') to this.id , since this already refers to the desired object, and you can directly access its id attribute using this.id
var whatYouWant = getNo($(this).attr('id')); function getNo(stringNo) { var parsedNo = ""; for(var n=0; n<stringNo.length; n++) { var i = stringNo.substring(n,n+1); if(i=="1"||i=="2"||i=="3"||i=="4"||i=="5"||i=="6"||i=="7"||i=="8"||i=="9"||i=="0") parsedNo += i; } return parseInt(parsedNo); }