I have a html look like this
<div id="mainDiv">
<p></p> //this can be any tag like <ul></ul> or <h1></h1>...
<ul></ul> //this can be any tag like <p></p> or <h1></h1>...
<div></div> //this too
</div>
I want to apply display:none
to the second element in #mainDiv (in this case it’s <ul></ul>
) so that it would be hidden.
How could I achieve it?
4
Answers
Use nth child selector with universal selector
*
You need the
:nth-child
selectorI believe this will help you.
I suggest you to use:
The :nth-child(n) selector matches every element that is the nth child, regardless of type, of its parent, while * is a selector who selects all elements but also select all elements inside another element.