[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread Ricardo
Short answer: $(".button").each(function(){ var icon = /icon(\w+)/.exec(this.className)[1].toLowerCase(); $(this).append(''); }); - ricardo On Apr 16, 9:58 am, jonhobbs wrote: > This might be hard to explain, but I need a way to loop through a > bunch of elements I've already selected a

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread jonhobbs
I will probably use seperate classes, but I found the answer. $(".button").each(function(el){ classStr = el.className; classes = classStr.split(' '); // Loop through classes and find the one that starts with icon }); On Apr 16, 4:05 pm, "Jonathan Vanherpe (T & T NV)" wrote

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread Jonathan Vanherpe (T & T NV)
jonhobbs 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 y

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread David
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 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 th

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread jonhobbs
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, "

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread Jonathan Vanherpe (T & T NV)
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.p

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread David
Actual after reading it again I like MorningZ's solution better. On Apr 16, 9:45 am, 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 a

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread David
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

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread jonhobbs
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.star

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread MorningZ
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(functi

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread jonhobbs
Thanks MorningZ, but does that dolve the problem? I'd still have to do a .hasClass() for each possible icon, wouldn't I? On Apr 16, 2:03 pm, MorningZ wrote: > It would be MUCH easier and cleaner to separate "icon" and "Star/ > PlusLeft/Right/Up/Down", a la: > > > > > > > > > If that's p

[jQuery] Re: How to pick out classes that start with a particular string.

2009-04-16 Thread MorningZ
It would be MUCH easier and cleaner to separate "icon" and "Star/ PlusLeft/Right/Up/Down", a la: If that's possible, that seriously would make your code easier and less complicated On Apr 16, 8:58 am, jonhobbs wrote: > This might be hard to explain, but I need a way to loop through a > b