I am looking for a JavaScript function that will add the class "current_highlight" when an element with the class "activo2" also has the class "active".
Here is my HTML code:
<div class="navbar-header">
<button type="button " class="navbar-toggle navbtn_webds btn_webds" data- toggle="collapse" data-target=".navbar-collapse">
<div class="navbtn_webds iconbar_webds iconbar-top_webds"></div>
<div class="navbtn_webds iconbar_webds iconbar-common_webds"></div>
<div class="navbtn_webds iconbar_webds iconbar-common_webds"></div>
</button>
<a id="site-title" class="navbar-brand brand_webds" href="http://localhost/webds" title="" rel="home"> <small></small></a>
</div>
<div class="navbar-collapse collapse">
<div class="navbar-collapse collapse">
<ul id="menu_principal" class="nav navbar-nav pull-right ">
<li id="menu-item-18" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-18">
<a title="Serviços" rel="m_PageScroll2id" href="http://localhost/webds/#servicos">Serviços</a>
</li>
<li id="menu-item-20" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-20">
<a title="Equipa" rel="m_PageScroll2id" href="http://localhost/webds/#equipa">Equipa</a>
</li>
<li id="menu-item-21" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-21">
<a title="Trabalhos" rel="m_PageScroll2id" href="http://localhost/webds/#trabalhos">Trabalhos</a>
</li>
<li id="menu-item-22" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-22">
<a title="Clientes" rel="m_PageScroll2id" href="http://localhost/webds/#clientes">Clientes</a>
</li>
<li id="menu-item-27" class="activo2 menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-27 active">
<a title="Blog" href="http://localhost/webds/?page_id=2">Blog</a>
</li>
<li id="menu-item-23" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-23">
<a title="Contactos" rel="m_PageScroll2id" href="http://localhost/webds/#contactos">Contactos</a>
</li>
</ul>
</div>
</div>
<!--/.nav-collapse -->
This is my JavaScript code:
$(document).ready(function () {
var CurrentPage = $('#menu_principal li').hasClass('.activo2');
var CurrentPage1 = $('#menu_principal li').hasClass('.active');
function CurrentMenu() {
$('.activo2').toggleClass('current_highlight');
}
if ( CurrentPage == true && CurrentPage1 == true) {
CurrentMenu();
}
});
And here is my CSS:
.current_highlight {background: #fcf2e0; color: #ff9933;}