JSFiddle - React, Tailwind, and code Playground
HTML
<div id="dvExpProvHolder" class="hidOverflow innerDivCenter">
<ul class="uSPStyle" id="uSPStyle">
<li class="setRelative">
<a class="tfLink clickMe current" title="Care" data-toggle=".tfLink1" id="" href="javascript:void(0);"><img src="theImages/imgMenu.png" id="imgFirstM" class="imgExpCol" />Care</a>
<ul class="uSPStyle uSPInner" style="width: 80%;">
<li><a class="tfLink clickMe" title="This is sub" data-toggle=".tf1SLink1" href="javascript:void(0);">This is sub</a></li>
</ul>
</li>
<li>
<a class="tfLink clickMe" title="Breast Cancer" data-toggle=".tfLink2" href="javascript:void(0);"><img src="theImages/imgMenu.png" id="imgFirstM" class="imgExpCol" />BC</a>
<ul class="uSPStyle uSPInner" style="width: 80%;">
<li><a class="tfLink clickMe" title="OUR" data-toggle=".tf1SLink2" href="javascript:void(0);">OUR LINK</a></li>
</ul>
</li>
<li>
<a class="tfLink clickMe" title="About" data-toggle=".tfLink3" href="javascript:void(0);">About</a>
</li>
<li>
<a class="tfLink clickMe" title="Anxiety" data-toggle=".tfLink4" href="javascript:void(0);">Anxiety</a>
</li>
<li>
<a class="tfLink clickMe" title="Services" data-toggle=".tfLink5" href="javascript:void(0);">Services</a>
</li>
</ul>
</div>
<div class="tfLink1 dispArtBody">
<tfText01>This is for first link</tfText01>
</div>
<div class="tf1SLink1 dispArtBody hideContent">
<tf1SText01>This is for first link sublink 1</tf1SText01>
</div>
<div class="tfLink2 dispArtBody hideContent">
<tfText02>This is for second link</tfText02>
</div>
<div class="tf1SLink2 dispArtBody hideContent">
<tf1SText02>This is for second link sublink 1</tf1SText02>
</div>
<div class="tfLink3 dispArtBody hideContent">
<tfText03>This is for third link</tfText03>
</div>
<div class=" tfLink4 dispArtBody hideContent">
<tfText04>This is for fourth link</tfText04>
</div>
<div class="tfLink5 dispArtBody hideContent">
<tfText05>This is for fifth link</tfText05>
</div>
<br...
CSS
* {
padding: 0;
margin: 0;
outline: 0;
/*text-decoration: none;*/
border: 0;
}
body {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-family: 'Verdana', 'Tahoma', 'Arial';
font-size: small;
font-weight: normal;
color: #333;
text-rendering: optimizeLegibility;
text-decoration: none;
}
html {
background: #FFF no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-family: 'Verdana', 'Tahoma', 'Arial';
font-size: small;
font-weight: normal;
color: #333;
text-decoration: none;
}
img {
border: 0;
border-style: none;
}
.imgExpCol
{
width: 13px;
height: 13px;
position: absolute;
left: 1%;
top: 2%;
z-index: 1000;
}
.brClear {
clear: both;
}
.brClearLeft {
clear: left;
}
.hideContent {
display: none;
}
.innerDivCenter {
margin: 0 auto;
}
ul.uSPStyle {
list-style-type: none;
width: 95%;
margin: 0px;
padding: 0px;
margin: 0 auto;
}
ul.uSPStyle li {
display: block;
margin-bottom: 1px;
background: #FFF;
text-transform: uppercase;
border-bottom: 1px solid #D5D5D5;
}
ul.uSPStyle li a.current, ul.uSPStyle li a#current, ul.uSPStyle li a:hover {
border-left: 4px solid #E55302;
border-right: 4px solid #E55302;
margin-left: -4px;
margin-right: -4px;
color: #e67e22;
box-sizing: border-box;
background: #FFEEE5;
}
ul.uSPStyle li a {
padding: 10px 20px;
line-height: 20px;
text-decoration: none;
display: block;
position: relative;
color: #175FA0;
margin-left: 0px;
margin-right: 0px;
transition: color 300ms linear;
-o-transition: color 300ms linear;
-ms-transition: color 300ms linear;
-moz-transition: color 300ms linear;
-webkit-transition: color 300ms linear;
}
.uSPInner {
display: none;
}
.myButton...
JavaScript
$(function () {
$('.myButton').click(function() {
var vStr = "1.0";
var vULSize = $("#uSPStyle li:not(li li)").size();
var vULSubSize;
if (vStr.indexOf('.') !== -1) {
var vSplit = vStr.split(".");
var vFirst = vSplit[0];
var vSecond = vSplit[1];
console.log(vFirst);
console.log(vSecond);
console.log(vULSize);
if (vFirst <= vULSize) {
alert("1");
alert($("#uSPStyle li:not(li li):eq(0)").find("a").eq(0).text());
$("#uSPStyle li:not(li li):eq(0)").find("a").eq(0).removeClass("current");
$("#uSPStyle li:not(li li):eq(" + vFirst + ")").find("a").eq(0).addClass("current"); //{need help}add the 'current' class to the parent LI
if ($("#uSPStyle li:not(li li):eq(" + vFirst + ")").find("a").closest("li").children("ul").length) {
alert("yes" + " " + $("#uSPStyle li:not(li li):eq(" + vFirst + ")").find("a").closest("li").children("ul").length);
vULSubSize = $("#uSPStyle li:not(li li):eq(" + vFirst + ")").find("a").closest("li").children("ul").length; //{DONE}get the size of the sub UL inside the above LI
$("#uSPStyle li:not(li li):eq(" + vFirst + ")").find("a").closest("li").children("ul").slideToggle();
if (vSecond <= vULSubSize) { //if the number is less than or equal to the size of the sub UL
alert("less than or equal to");
//display the content for the CHILD item
$("#uSPStyle > li:eq(" + vFirst + ") > ul > li:eq(" + vSecond + ") a").addClass("current");
}
else {
alert("number too high");
//display the content for the PARENT item
}
}
else {
alert("no");
}
}
}
else {
//{need help}remove 'current' class from the existing parent LI
$("#uSPStyle li:eq(" + vFirst + ")").addClass("current"); //{need help}add the 'current' class to the parent...