PDA

View Full Version : HTML : Hide a list if no item inside


dmegatool
2012-09-21, 10:55
Hey guys !
I need to hide a <li> (it's a menu item with sub-items) if there's no other <ul><li> or <a> in it. Can it be done in php or do I need to use Javascript ? I'm pretty beginner in both, anyone can help me out on this one ?

The item that needs to be removed can be set to css display:none, it's not critical if it's rendered then hidden...

So the "class1" <li> wouldn't be shown :

<ul>
<li class="class1">This is a list item</li>
</ul>

"class2" <li> would be shown, class3 not:

<ul>
<li class="class2"><a href="#">Open sub menu</a>
<ul>
<li class="class3">This is a subitem</li>
</ul>
</li>
</ul>

Gargoyle
2012-09-21, 11:38
Mike life easy on yourself and add some extra classes with php.

Also, there are a shit-tonne of javascript + css dropdown, pop-up, slide-out bound in menu systems if you search around google.

http://www.alistapart.com is always a good place to start for this kind of thing.