Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda