Instead of using two different CSS classes, you can use one and use the CSS Attribute Selector . This selector applies to the CSS selector you want to use it with, for example .game-star ul li[class=Active] . It tells CSS to look for an element named game-star , which has a child element node ul and ul , which has a child element node of li WITH attribute class=Active . This is very convenient for simplifying work with JavaScript.
Therefore, instead of managing and changing class names using JavaScript, you only need to add or remove the class=Active attribute on yours. Now, the example I gave you is actually an example of bad practice. Something like this would be a good practice .game-star ul li[data-active=Active] would be a better practice. The reason why you never want to use CLASS ATTRIBUTE IN ATTRIBUTE SELECTOR , why? This is because it has already been built this way ... .game-star ul li.Active You can combine the selectors, name and identifier together to add more emphasis to your target. You can read about it here .
So my recommendation would be for your code:
HTML
<div class="game-star" style="height: 198px; overflow: hidden;"> <ul> <li data-active="true"> <div class="game-star-icon"></div> <h3 class="winner-name">Major Millions<br>RMB 1000.00</h3> </li> <li> <div class="game-star-icon"></div> <h3 class="winner-name">Major Moolah<br>RMB 3,266.41</h3> </li> <li> <div class="game-star-icon"></div> <h3 class="winner-name">Major Moolah Isis<br>RMB 4,982.78</h3> </li> <li> <div class="game-star-icon"></div> <h3 class="winner-name">ๅๅคง่ดข<br>RMB 8,888.88</h3> </li> <li> <div class="game-star-icon"></div> <h3 class="winner-name">ๆๅๆๅๆๅๅๅ<br>RMB 9,999.99</h3> </li> </ul> </div>
CSS
.game-star ul li[data-active=true] h3 { font-size:14px; color:#fff; line-height:24px; float:left; font-weight:100; margin-top:8px; }
EDIT: If you still want to do it your own way, here's a fiddle for you. Do not forget to change the colors the way you want! :)
Jsfiddle
Matthew
source share