__(Added `[code]…[/code]
I have mobile menu in which categories and subcategories are displayed one after another in the sequences. The categories are <li>s of one <ul>, and subcategories are <ul>s of each category <li>, and they have own <li>s of subcategory list like below:
Categories
[code]
<ul>
<li class=”cats” onclick = “Display()” >Car
<ul class=”subs”>
<li>New car<li>
<li>Rent car<li>
<li>Car parts<li>
</ul>
</li>
<li class=”cats” onclick = “Display()” >Digital
<ul class=”subs”>
<li>Notebooks<li>
<li>Tablets<li>
<li>Phones<li>
</ul>
</li>
</ul>
By default, I do not display subcategories in menu
[code]
.subs{
display: none;
}
And when clicking on any of the categories, that category’s subcategories must be seen.
I tired this function in JS which didn’t work.
[code]
function Display(){
var catitems = document.getElementsbyClassName(‘cats’);
var i;
for(i =0; i <catitems.length; i++){
catitems[i].children.style.display = “block”; (also tried this: catitems[i].firstChild.style.display = “block”;
}
}
Please, ignore letter and similar minor mistakes here as I hadn’t problem with them in Visual Studio.
Why doesn’t it work? What would be JS solution for this?