Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to apply CSS in odd childs of parent node using jQuery ?

  • Last Updated : 21 Sep, 2021

In this article, we will see how to set styles in the odd child of parent element using jQuery. To set the style on the odd child of the parent, we use jQuery :nth-child(odd) selector.

The :nth-child(odd) selector is used to select every element that is the odd child of its parent element.



Approach: First, we create an HTML element containing a div element. This div element contains some paragraph element, then we use :nth-child() selector to select all odd position child of the parent element.



<!DOCTYPE html>
    <script src=
        div {
            font-size: 18px;
            font-weight: bold;
        p {
            margin-left: 50px;
        $(document).ready(function() {
                backgroundColor: "green",
                color: "white",
                padding: "5px 15px",
                display: "table"
    <h1 style="color: green;">GeeksforGeeks</h1>
        How to apply CSS in odd childs of parent 
        node using jQuery library?
        <p>Data Structure</p>
        <p>C++ Programming</p>
        <p>Web Technology</p>


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!