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

153
Views
Want to check for all DIV ID and match with anchor link in UL LI a[href], if match found then add a class to the LI items

I really am facing a complex situation here.
I have created an event page. Each page will have multiple sections like CULTURE, FOOD, SPORTS and each section will have events. I already set a system that has a nav tag, inside the nav tag we have ul li a[#anchor-links]. I have this code that will look for Div id when it is visible it will add an active class to that list item.
Now, in the sidebar, under each li item, I create 12 more li items for months. That will DISPLAY NONE initially and display inline-block when the mother LI has a class ACTIVE. What I am trying is to find all DIV ID for a month as well, and compare with these 12 li a[href], then months we have events on, I want that those link active and show a special class.
These are ID I added
Culture - #culture . Events under culture like #culture-jan,#culture-feb
Food - #food. Events under food like #food-jan,#food-fed ....
This is the JQuery I am using so far

<script>
window.addEventListener('DOMContentLoaded', () => {

  const observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
      const id = entry.target.getAttribute('id');
      if (entry.intersectionRatio > 0) {
        document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.add('active');
      } else {
        document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.remove('active');
      }
    });
  });

  // Track all sections that have an `id` applied
  document.querySelectorAll('div[id]').forEach((div) => {
    observer.observe(div);
  });
  
});
</script>


Please anyone, help. Thanks
about 4 years ago · Juan Pablo Isaza
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!