Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS: Specifying current element in the menu

I have a menu:

 <ul>
    <li id="active"><a href="/">Головна</a></li>
     <li><a href="/about/">Про компанію</a></li>
     <li><a href="/work/">Діяльність</a></li>
     <li><a href="/initiative/">Ініціативи</a></li>
     <li><a href="/statti/">Статті</a></li>
 </ul>

Can you suggest a way to change id=active attribute for this list. If for example I clicked on about, I want this li element to be marked as active.

Thanks

like image 200
Oleg Tarasenko Avatar asked Jan 23 '26 21:01

Oleg Tarasenko


1 Answers

There is an elegant css method of styling the currently active navigation state without any javascript or server side support. Basically one id (e.g. as body id attribute) that uniquely identifies the navigation state is enough to create css selectors that highlight the active state.

like image 101
Josef Pfleger Avatar answered Jan 25 '26 11:01

Josef Pfleger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!