1

How do I select (for instance) the 2nd h3 element of my body without affecting the elements between them?

nth-of-type doesn't work because it will select the first parent!

Here's my jsfiddle (sorry because it's foreign and the code is not shortened)

<http://jsfiddle.net/tg7of5sp/>

1 Answers1

2

nth-of-type()

The :nth-of-type(n) selector matches every element that is the nth child, of a particular type, of its parent.n can be a number, a keyword, or a formula.

See Refrence

Working Demo Selecting 2nd h3 of body

body>h3:nth-of-type(2){
    color:red;
    }
<body>
  <h3>1st Heading h3</h3>
  <div>
    
  <h3>div 1st Heading h3</h3>
   <h3>div 2nd Heading h3</h3>

    </div>
  
  <h3>2nd Heading h3</h3>
  </body>
A.B
  • 20,110
  • 3
  • 37
  • 71