you would imagine this would be easy to implement, but oh well..
anyway, I have an element to which classes are added or removed based of interaction on the site.
Use this one...
var classes = $('#mydiv').attr('class').split(/\s+/);
This will give you an array of all the classes applied to your element. For the length you can simply extend it as
var classes = $('#mydiv').attr('class').split(/\s+/).length;
Cheers