Im using tabbed content on my page (SEE MY FIDDLE)
Now the tabbed content makes use of <ul><li>
elements to display the different tabs. Inside one of these tabs I would like to add a <ul><li>
list however the list is not getting displayed correctly I suspect because:
- The jquery is effecting it
- It is nested inside another li elements
Any idea how I can fix this?
please look at fiddle to fully understand my question
Advertisement
Answer
You can use the >
, child selector to refine the selectors to match only the <li>
elements immediately under <ul id="tab">
:
JavaScript
x
7
1
ul#tab > li {
2
display: none;
3
}
4
ul#tab > li.active {
5
display: block;
6
}
7
JavaScript
1
2
1
$("ul#tab > li:nth-child(" + nthChild + ")").addClass("active");
2
https://jsfiddle.net/63og0jue/
Without >
, the selectors will match any <li>
descendant of <ul id="tab">
:
JavaScript
1
12
12
1
<ul id="tab">
2
<li><!-- --></li>
3
<li>
4
<!-- -->
5
<li>one</li>
6
<li>Two</li>
7
<li>THree</li>
8
<!-- -->
9
</li>
10
<li><!-- --></li>
11
</ul>
12
ul#tab li:nth-child(1)
, for example, matches both of these as the first-child of their respective parents:
JavaScript
1
2
1
<li>one</li>
2
JavaScript
1
4
1
<li>
2
<p>HI There Enter personal Info</p>
3
</li>
4