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
Carefull with $('#dialog li[class^="C"]')
! It will only match elements, whose class attribute starts with "C" not ones with a class starting with C. For example it will not match .
AFAIK what you want is not possible mit jQuery alone. You would need to loop through the classes and check each separatly. Something like:
$('#dialog li').filter(function(){
var classes = this.className.split(/\s/);
for (var i = 0, len = classes.length; i < len; i++)
if (/^C/.test(classes[i])) return true;
return false;
}).each( ... )
Alternativly you should consider changing your approach, and give all elements an additional class and filter by that. This has the addvantage that it can also be used in CSS:
-
-
-