Is there a way to define styles for a combination of classes? For example, I'd like my HTML to look like this, but the output to render in the appropriate color:
<span class="red">Red Text</span><br/>
<span class="green">Green Text</span><br/>
<span class="red green">Yellow Text</span><br/>
Edit: The above seems to be confusing people when it was just an example; so here is another example:
<style>
.style1 { background-color: #fff; }
.style2 { background-color: #eee; }
.style1.highlight { color: red; }
.style2.highlight { color: blue; }
</style>
<ul>
<li class="action style1">Do Action 1</li>
<li class="action style2">Do Action 2</li>
<li class="action style1 highlight">Do Action 1</li>
<li class="action style2 highlight">Do Action 2</li>
</ul>
<script language="javascript" type="text/javascript">
$("li.action").bind("click", function(e) {
e.preventDefault();
// Do some stuff
$(this).addClass("highlight");
$(this).unbind("click");
});
</script>
Again, this is just an example, so don't get hung up on alternating elements or anything like that. What I'm trying to avoid is having to duplicate the bind function for each different styleN or having to write an elseif structure that checks for each styleN class. Unfortunately this code doesn't work in IE 6 or 7 - the highlighted text for both .style1 and .style2 elements end up being blue.