Sohil Shah Sohil Shah - 3 months ago 6
Sass (Sass) Question

How to select the odd-child in any sequence inside the body?

I have an html structure something like this.enter image description here

How can i achieve the background-color to be red or blue based on their sequence in the body?

Answer

With jQuery:

$(".my-class").filter(":odd").css("background","red");
$(".my-class").filter(":even").css("background","blue");
  .common { padding: 20px 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="my-class common"></section>

    <div class="">
        <section class="my-class common"></section>
    </div>

    <div class="">
        <div>
            <section class="my-class common"></section>
        </div>
    </div>

    <section class="my-class common"></section>