Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!