This should be the simplest way:
var id = this.id.replace(/[^\d]/g,'')*1;
It returns any digits from the ID attribute as a number
(*1
does the conversion, similar to parseInt
). In your example:
$("#my-div a").click(function(){
var n = this.id.replace(/[^\d]/g,'')*1;
alert(n); // alerts any number in the ID attribute
alert(typeof n) // alerts 'number' (not 'string')
});