I need to loop through some elements in the page and then, for each one, if it had a class beginning with, for example, \"C\", do something.
$(\'#dialog li\').e
Try the Attribute Starts With Selector. As a bonus, there is no need for the extra if.
$('#dialog li[class^="C"]').each(function() { // do something });