Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:46:00+00:00 2026-06-02T22:46:00+00:00

Short question: how do you use JS/jquery to return index of an element within

  • 0

Short question: how do you use JS/jquery to return index of an element within some , given its class name?

Long question: I’ve been at this problem for a few hours and I can’t seem to find a solution. I have a WordPress site, which uses a theme that utilizes superfish and lavalamp jquery. the lavalamp works fine for categories and pages, but for a single post, the lavalamp keeps going to the first item of the list.

It’s worth noting that I have done some serious googling around, but the answers are either too old, or they don’t work for my case. I have jQuery 1.7.1, lavaLamp 1.3.3 (updating to 1.3.5 breaks everything), and superfish 1.4.8.

I’ve narrowed it down that the script that calls the lavaLamp plugin isn’t returning the correct index of the current category for a single post. Here’s what it looks like:

var active_subpage = jQuery('ul.sf-menu ul li.current-cat, ul.sf-menu ul li.current_page_item').parents('li.top-level').prevAll().length;
var isHome = <?php if (is_front_page() || is_home()) echo('1'); else echo('0'); ?>; 

if (active_subpage) jQuery('ul.sf-menu').lavaLamp({ startItem: active_subpage });
else if (isHome === 1) jQuery('ul.sf-menu').lavaLamp({ startItem: 0 });
else jQuery('ul.sf-menu').lavaLamp();

How do I modify the script so that it returns the index of the “current-cat” for that post?

I’ve pasted what I think you’d need HERE. You can take a look at the live site HERE.

Thank you very much in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:46:02+00:00Added an answer on June 2, 2026 at 10:46 pm

    Your active_subpage query only works for elements that are selectable from a submenu, the first selector doesn’t seem like it will match anything, because its looking for the .current-cat in a sub-menu, when it is actually a top menu.
    I think it will work if you remove the second <ul> in the first selector of the active_page query.
    EDIT:
    I see the problem, the li.current-cat is the parents('li.top-level') that we’re looking for.
    The two queries may need separating.
    Or change the first selector to include a descendant (<a>) so that parents('li.top-level') would make a match

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The short form of this question: When, if ever, is it appropriate to use
Short question: Do any of MS's built in Data Objects support INotifyPropertyChanged? Long explination:
Short question - how do you define your view models? Here are some of
Short question. How do you go about transposing UML diagrams into code? The class
Short question: I'm trying to make that in a given page (uses tabs) back
Pretty simple question. Its just some advice based on personal opinion and best practice.
Short question: Is it possible to do a redirection, say when a user isn't
Short question: Is the parent of an entity group included in that entity group
Short Question Has anyone had an issue when right clicking files (.c/.h/etc..) and the
Short question: Can anyone tell me what the requirements (especially when it comes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.