Hey all,
I'm working on a site that offers some customizability regarding elements
colors (background & font). Rather then setting the color with .css(), I use
classes like color-red, color-green, etc (and of course, red is not the css
"red" and green is not the css "green"). I find it much cleaner since  I
need not have color values referenced within javascript or php (it's simply
in the css).

However, the code seems unnecessarily bloated for switching classes. What
would be very useful imo, is to have hasClass accept regexp & return the
array of found classes and also a .replaceClass() function that would change
a class into another. That way I could do the following:

var colorClasses = $.hasClass(/color-.+/);
if (colorClasses!==false) {
  var currentColorClass = colorClasses[0];
}
// Do stuff with the color class
$.replaceClass(currentColorClass,"color-"+newColor);

As of today, I have only two solutions:
- keep the current color using $.data() or any other custom data container
- OR search the class attribute by hand (hoping classes are in a specific
order, you can imagine the mess)

If that wasn't bad enough, after that, to replace the class, I have to call
$.removeClass() and $.addClass() which seems pretty inefficient to me.

I know I could probably do a plugin for that but I have the feeling that, if
embedded in jQuery with its class related code, it would be much more
efficient.

I also know I could switch back to the .css("background-color",color) but it
kinda defeats the purpose of having the presentation information in the css
and ONLY in the css which I find pretty nice for maintenance.

Yes, and finally, am I crazy or couldn't this be quite useful?

Take care, all,

-- Julian

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to