Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style for odd displayed children

I'm looking a way to apply some specific styles on odd (or even) children that are displayed (so excluding hidden children). Optionnaly, if that styles applied when hidden children become displayed it would be perfect!

Here is a live sandbox : http://jsfiddle.net/zrges/1/

And here is what I visually want : http://jsfiddle.net/qJwFj/ (of course, it's only a display example, don't take care of the crappy code that I wrote for that)

I can't manage with to good pseudo classes, css selectors to handle that.

I hope to have a full css/html solution (not a js/php one, which is easier)

Thank you very much!

like image 474
Guile Avatar asked Nov 26 '22 00:11

Guile


1 Answers

Check this out : http://jsfiddle.net/qbXVV/18/


HTML:

<button id="toggle">Toggle it!</button>
 <table>
  <tr class="sub"><td>Row 1</td></tr>
  <tr class="tag"><td>Row 2</td></tr>
  <tr class="sub"><td>Row 3</td></tr>
  <tr class="tag"><td>Row 4</td></tr>
  <tr class="sub"><td>Row 5</td></tr>
  <tr class="tag"><td>Row 6</td></tr>
  <tr class="sub"><td>Row 7</td></tr>
 </table>​


CSS:

     tr:nth-of-type(even),.bg {
        background-color: gray;
     }

    .hidden {
        display:none;   
    }​


JS:

$(document).ready(function () {
$('#toggle').click(function () {
    $('.tag').toggleClass("hidden");
    $(".sub:nth-child(4n+1)").toggleClass("bg");
});
});​
like image 116
Ankit Avatar answered Nov 27 '22 13:11

Ankit