.hasClass() would be better, particularly for 'collection-original' which doesn't have mutable extensions. If you separated the "collection-new" class (and similar) from the serial number, then you could separate the class tests from the ordering logic. It's also a bit dangerous to use underspecified regexs: what happens if another library adds a class to some element called "collection-newish"? unlikely example, but further down you have a class called "list", which could very easily be a substring of some other class name.