0
I’m tired of always changing the navbar
of all my pages, and I decided to create a file for navbar
and always give a include
on the pages to make it easier to add/remove items!
Only, my question is whether it has a system in PHP
or JavaScript
that can identify the page to set the class 'active'
in the <li>
of navbar
corresponding to the current page!
Navbar’s code is as follows::
<div class="container">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
<li class="active clash"><a href="/">Início</a></li>
<li class="clash"><a href="/ferramentas/gerador-de-emblema">Gerador de Emblemas</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</div>
For example, I’m on the page HOME
! Say the id
of body
is "1"
.
A script could capture this id
and assign the class active
to the <li>
with the id "1"
!
Dude, I don’t know why, but I totally ruled out the . val() option in my mind so I ran out of ideas kkkk, I’m gonna try this with jquery!
– Sampaio Leal
truth bro, o . val() does not work with attr()! I removed the . val() and it worked, worked perfectly!
– Sampaio Leal
I didn’t even test it, if I had tested it, I had noticed it, . val() removed!
– Vinicius Colares
I think Javascript is the best option, I thought in PHP to do some kind of class or sla, never messed with classes!
– Sampaio Leal