cant you just get the className and then do a split on it with spaces
as the deliminator?

On Apr 16, 9:53 am, jonhobbs <jon.hobbs.sm...@gmail.com> wrote:
> Both of those would work as solutions to this problem.
>
> However, I'd still really like to find out if there's a way to get a
> list (array?) of all of the classes that are currently attached to an
> element and loop through them.
>
> It doesn't dound like it should be so hard.
>
> Jon
>
> On Apr 16, 3:50 pm, "Jonathan Vanherpe (T & T NV)" <jonat...@tnt.be>
> wrote:
>
>
>
> > I'm not really sure why you're not just doing this in pure css.
>
> > .button {
> >         padding-right: 20px;
> >         background-position: center right;
> >         background-repeat: no-repeat;}
>
> > .iconstar       {       background-image: url(star.png);}
> > .iconplus       {       background-image: url(plus.png);}
>
> > Am I missing something here?
>
> > Jonathan
>
> > David wrote:
> > > The problem I see is what happens when there is more than one class?
> > > Your icon call may not be the first class. in which case you would not
> > > have selected it. But it was still supposed to get an icon. Would it
> > > be possible to give the divs that are supposed to receive the icons a
> > > generic class then use an attribute to define what icons it is
> > > supposed to have. You could even reduce the amount of code that you
> > > have to output.
>
> > > <div class="icon button" img="Star"></div>
>
> > >  $(".button").each(function(){
> > >      if ($(this).hasAttribute("img") && $(this).attr("img") != "")
> > > {
> > >       $(this).append("<IMG SRC='" + $(this).attr("img") + ".gif'>");
> > > }
> > > )
>
> > > I know that it is probably not the best code as you are using
> > > attibutes that do not fall into the dom standards but it looks like it
> > > would get the job done.
>
> > > On Apr 16, 8:51 am, jonhobbs <jon.hobbs.sm...@gmail.com> wrote:
> > >> Here is some psuedo-code for what I'm trying to achieve...
>
> > >> $(".button").each(function(){
>
> > >>     // Get an array of classes that are attached to $(this)
>
> > >>     // Loop through the array classes
> > >>     for (items in array){
>
> > >>         // check to see if the class starts with "icon"
> > >>         if(className.startswith('icon')){
>
> > >>             // remove the first 4 characters
> > >>             var iconName = className.substring(4, className.length);
>
> > >>             // Use the remainder to append the image
> > >>             $(this).append("<IMG SRC='" + iconName + ".gif'>");
>
> > >>         }
>
> > >>     }
>
> > >> });
>
> > >> That way, I could have hundreds of possible icons and I wouldn't have
> > >> to have hundreds of IF statements and hundreds of calls to .hasClass()
>
> > >> On Apr 16, 2:16 pm, MorningZ <morni...@gmail.com> wrote:
>
> > >>> Well, other than asking whether or not an object "has a class or
> > >>> doesn't", there isn't much you can do that check each class name
> > >>> so like (and this assumes your original HTML, not the separated class
> > >>> name) :
> > >>> var icons = ["Star", "Plus", "Left", "Right", "Up", "Down"];
> > >>> $("div.button").each(function() {
> > >>>       var $dv = $(this);
> > >>>       $.each(icons, function() {
> > >>>            if ($dv.hasClass("icon" + this)) {
> > >>>                  $dv.append('<img src="Images/' + this + '.gif"
> > >>> alt="" />');
> > >>>                  return false;
> > >>>            }
> > >>>       });
> > >>> });
> > >>> On Apr 16, 9:08 am, jonhobbs <jon.hobbs.sm...@gmail.com> wrote:
> > >> - Show quoted text -
>
> > --
> > Jonathan Vanherpe - Tallieu & Tallieu NV - jonat...@tnt.be- Hide quoted 
> > text -
>
> - Show quoted text -

Reply via email to