Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Add 'current-menu-item' class to div based on URL

I'm trying to add the class current-menu-item to the following div:

<div class="menu-item menu-item-type-custom menu-item-object-custom jet-custom-nav__item jet-custom-nav__item-6068">

Afterwards it should be

<div class="**current-menu-item** menu-item menu-item-type-custom menu-item-object-custom jet-custom-nav__item jet-custom-nav__item-6068">

This is how my .js looks like so far

jQuery(document).ready(function() {
    if(window.location.href.match('harmonikapuls.com/konto/adressen/rechnungsadresse')){
        $("menu-item.menu-item-type-custom.menu-item-object-custom.jet-custom-nav__item.jet-custom-nav__item-6068").addClass("current-menu-item");
    }
});

Basically I just want not a specific URL but everything after the slug /adressen/ this was just for trying. I call my function over my function.php

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You must include dots when using the jQuery selector to find elements by class names.

Furthermore, since you're selecting a div that contains all of the named classes, they must not be separated by space, so $(".menu-item.menu-item-type..."). If you separated the class names by space, it would look for the children of the previous class name. See the answer here.

Also, it would be wiser to add a unique id to the div element by adding an attribute id="myDiv" and then use a hashtag in the selector: $("#myDiv") - it would be more efficient and clearer. If you don't want to use an id, you can select the element just by the class that uniquely identifies it, so for example $(".jet-custom-nav__item-6068").

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda