0
I have the bottom menu, which is contained in the page empresas.php and "Edit" a company becomes editar-empresa.php?id=x:
The function that adds the class active to the current page is the following:
(function() {
var nav = document.getElementById('menu'),
anchor = nav.getElementsByTagName('a'),
current = window.location.href.split("?")[0];
for (var i = 0; i < anchor.length; i++) {
if(anchor[i].href.split("?")[0] == current) {
anchor[i].children[0].className = "active";
}
}
})();
That is, the "Companies" section will only remain highlighted if it is on the page empresas.php, but I need you to remain detached when going to the subsection editar-empresa.php?id=x. What must I do to achieve such a goal?
HTML:
<div id="menu">
<nav>
<ul>
<a href="emissor-nfe.php"><li>Emissor NF-e</li></a>
<a href="empresas.php"><li>Empresas</li></a>
<a href="clientes.php"><li>Clientes</li></a>
<a href="produtos.php"><li>Produtos</li></a>
<a href="transportadoras.php"><li>Transportadoras</li></a>
<a href="logout.php"><li>Sair</li></a>
</ul>
</nav>
</div>

If you can change the file name to
editar-empresas.php, could do something likeif (current.indexOf(anchor) >= 0). Thus the text would be soughtempresas.phpineditar-empresas.phpand, if you think, define as active, but I do not know if it is a very good solution.– Woss
Hello @Andersoncarloswoss, could further detail your solution?
– lucasbento
As soon as I get some free time I’ll see if I can give you an answer.
– Woss
Remembering that using elements
awithin aulis syntactically and semantically wrong. If your goal is to make the wholelirespond to the link event, see this reply: https://answall.com/a/221187/5878– Woss