I have titles and they have siblings one of them which is a div
clearfix, in this div
there is a ul
of box-content and there are items that some of them are hidden and some of them are shown there is a ol
list that should be clicked on it, if there is no items in the list of items in this example Batteries it should not show the title header (the div class name which is reltitles
) remember that we have many title headers and box contents and divs so it should work in general not a specific one
<div class="reltitles" id="Batteries" style="display:block;">
<font class="resultHeader">(2) Batteries </font>
</div>
<div class="clearfix" value="Batteries" name="Batteries" id="Batteries">
<ul class="box-content" id="Batteries">
<li id="50-80" class="item first" style="display: none;"></li>
<li id="50-80" class="item first" style="display: none;"></li>
<li id="20-50" class="item">
something here
</li>
</ul>
</div>
the list to be clicked:
<ol id="myAnchor">
<li><a id="0-20" href="#">0.00 - 20.00</a></li>
<li><a id="20-50" href="#">20.00 - 50.00</a></li>
<li><a id="50-80" href="#">50.00 - 80.00</a></li>
<li><a id="80-100" href="#">80.00 - 100.00</a></li>
<li><a id="All" href="#">All</a></li>
</ol>
this is my java script code that does not work I debugged with chrome tools and still I couldn't figure it out:
j$("#myAnchor li a").click(function(){
var prices = j$(".box-content li");
prices.show();
if (this.id != "All")
{ prices.not(j$(".box-content li[id='"+this.id+"']")).hide();
}
var tt=document.getElementsByClassName("reltitles");
for(k=0;k<tt.length;k++)
{
var clear=tt[k].nextElementSibling;
var list=clear.childNodes[1].children;
j=0;
for(i=0;i<list.length;i++)
{
if(list[i].style.display=="none")
{
j++;
}
if(j==list.length)
{
tt[k].style.display="none";
}
else{ tt[k].style.display="block";}
}
}
});
UPDATe: the ids are unique they will be generated by php code I just wanted to show it simpler