String.prototype.strint

Do you also have the bad habit of storing identificational values as an HTML element attribute? I do, because sometimes $.data(); just doesn’t cut it. In order to have enough ID’s for different types of elements (for my Affinity prototype I used images, groups and titles, all with ID’s), you need some sort of prefix. But then what, how do you get the integer from the ID attribute when it’s a non-parseInt() String? Like this:

String.prototype.strint = function()
{
	return parseInt(this.replace(/[^0-9.]/g, ""));
};

Usage:

var s = "group_42";
var i = s.strint();
// i = 42

Comments Closed