These above methods just seem too complex for this problem. I don't think you have to append the string to the document. I would simply just separate the string by the substring 'class="' and do work from there.
var tags = mystr.split("class=\"");
var classes = new Array();
var endclass;
for (var i=0; i<tags.length; i++) {
endclass = tags[i].indexOf("\">");
if (endclass > -1) {
var newclass = tags[i].substring(0,endclass).split(" ");
classes = classes.concat(newclass);
}
}
Here is my jsfiddle: http://jsfiddle.net/nmkjvqmL/
This however, is assuming that the class is at the end of the tag. If it is not always at the end of the tag you can change this line: endclass = tags[i].indexOf("\">");
to this endclass = tags[i].indexOf("\"");
However, this will include the string class="whatever" that is not in a tag, so you will have to make sure this text is not in the string.