title: Chaining CSS classes in IE6 - Trying to find a jQuery solution?
body: <p>tl;dr = "Anyone know how to apply chained classes for IE6 using jQuery or similar?"</p>
  
  <p>Right,</p>
  
  <p>perhaps I ask the impossible? I consider myself fairly new to Javscript and jQuery, but that being said, I have written some fairly complex code recently so I am definitely getting there... however I am now possed with a rather interesting issue at my current freelance contract.</p>
  
  <p>The previous web coder has taken a Grid-960 approach to the HTML and as a result has used chained classes to style many of the elements. The example below is typical of what can be found in the code:</p>
  
  <pre><code>&lt;div class='blocks four-col-1 orange highlight'&gt;Some content&lt;/div&gt;
  </code></pre>
  
  <p>And in the css there will be different declarations for: (not actual css... but close enough)</p>
  
  <pre><code>.blocks {margin-right:10px;}
  .orange {background-image:url(someimage.jpg);}
  .highlight {font-weight:bold;}
  .four-col-1 {width:300px;}
  </code></pre>
  
  <p>and to make matters worse... this is in the CSS:</p>
  
  <pre><code>.blocks.orange.highlight {background-colour:#dd00ff;}
  </code></pre>
  
  <p>Anyone not familiar with this particular bug can read more on it here: <a href="http://www.ryanbrill.com/archives/multiple-classes-in-ie/" rel="noreferrer">http://www.ryanbrill.com/archives/multiple-classes-in-ie/</a> it is very real and very annoying.</p>
  
  <p>Without wanting to go into the merrits of not chaining classes (I told them this, but it is no longer feasible to change their approach... 100 hand coded pages into a 150 page website, no CMS... sigh) and without the luxury of being able to change the way these blocks are styled... can anyone advise me on the complexity and benefits between any of my below proposed approaches or possible other options that would adequately solve this problem.</p>
  
  <p><strong>Potential Solution 1</strong></p>
  
  <p>Using conditional comments I am considering loading a jquery script only for IE6 that:</p>
  
  <ol>
  <li>Reads the class of all divs in a certain section of the page and pushes to an array</li>
  <li>creates empty boxes off screen with only one of the classes applied at a time</li>
  <li>Reads the applied CSS values for each box</li>
  <li>Re-applies these styles to the individual box, somehow bearing in mind the order in which they are called and overwriting conflicting instructions as required</li>
  </ol>
  
  <p><strong>Potential Solution 2</strong></p>
  
  <ol>
  <li>read the class of all divs in a certain section of the page and push to an array</li>
  <li>Scan the document for links to style sheets</li>
  <li>Ajax grab the stylesheets and traverse looking for matching names to those in class array</li>
  <li>Apply styles as needed</li>
  </ol>
  
  <p><strong>Potential Solution 3</strong></p>
  
  <ol>
  <li>Create an IE6 only stylesheet containing the exact style to be applied as a unique name (ie: class='blocks orange highlight' becomes class='blocks-orange-highlight')</li>
  <li>Traverse the document in IE6 and convert all spaces in class declarations to hyphens and reapply classes based on new style name</li>
  </ol>
  
  <p>Summary: </p>
  
  <p>Solution 1 allows the people at this company to apply any styles in the future and the script will adjust as needed. However it does not allow for the chained style to be added, only the individual style... it is also processor intensive and time consuming, but also the most likely to be converted into a plugin that could be used the world over</p>
  
  <p>Solution 2 is a potential nightmare to code. But again will allow for an endless number of updates without breaking</p>
  
  <p>Solution 3 will require someone at the companty to hardcode the new styles every time they make a change, and if they don't, IE6 will break.</p>
  
  <p>Ironically the site, whilst needing to conform to IE6 in a limited manner, does not need to run wihtout javascript (they've made the call... have JS or go away), so consider all jQuery and JS solutions to be 'game on'.</p>
  
  <p>Did I mention how much i hate IE6?</p>
  
  <p>Anyway... any thoughts or comments would be appreciated.</p>
  
  <p>I will continue to develop my own solution and if I discover one that can be turned into a jQuery plugin I will post it here in the comments.</p>
  
  <p>Regards,</p>
  
  <p>Mike.</p>
  
  <p><em>edit: added tl;dr to the top.</em></p>