It would be MUCH easier and cleaner to separate "icon" and "Star/ PlusLeft/Right/Up/Down", a la:
<div class="button icon Star"></div> <div class="button icon Plus"></div> <div class="button icon Left"></div> <div class="button icon Right"></div> <div class="button icon Up"></div> <div class="button icon Down"></div> If that's possible, that seriously would make your code easier and less complicated On Apr 16, 8:58 am, jonhobbs <jon.hobbs.sm...@gmail.com> wrote: > This might be hard to explain, but I need a way to loop through a > bunch of elements I've already selected and for each one find classes > that start with the word "icon". So for example I might have the > following elements > > <div class="button iconStar"></div> > <div class="button iconPlus"></div> > <div class="button iconLeft"></div> > <div class="button iconRight"></div> > <div class="button iconUp"></div> > <div class="button iconDown"></div> > > So, I begin by selecting the elements and looping through them.... > > $(".button").each(function(){ > // Some code here > > }); > > Now, I could put the following code in the loop... > > if ($(this).hasClass("iconStar")){ > $(this).append("<IMG SRC='Images/star.gif'>"); > > } > > I would then have to repeat that for each possible icon, which seems > very inefficient. > > What I'd like to do in the "each" loop is just cycle through all the > classes that $(this) has and pick out the one that begins with ICON > and then use that to append the image. > > Can anyone help?