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 7499149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:43:17+00:00 2026-05-29T19:43:17+00:00

Trying to build a plugin effect that will some what look better than this

  • 0

a simple demo

Trying to build a plugin effect that will some what look better than this when its ready.

Note the numbers 0, 1, 2.

They are simple indication of level the element currently is in. 0 denoting the top level and 2 the least. Check the demo here.

Every time I click on a column, it becomes the main columns (thus gaining 0 as its level) and rest of the columns are leveled using the same rule. If you see the snippet I am using to do that, it is very ugly.

$("li").click(function() {
    $(this).html(0);

    //denote the first level
    $(this).next().html(1);
    $(this).prev().html(1);

    //denote the second level
    $(this).next().next().html(2);
    $(this).prev().prev().html(2);    

    //denote the third level
    $(this).next().next().next().html(3);
    $(this).prev().prev().prev().html(3);    

    //denote the fourth level
    $(this).next().next().next().next().html(4);
    $(this).prev().prev().prev().prev().html(4);    
});

I absolute hate it. What if the number of my column grow, I am in trouble then. I need something neat to traverse up the tree structure (i.e like .closest("li")) and below as well.
With every column, getting their specific level of markup once the main column changes.

  • 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-05-29T19:43:20+00:00Added an answer on May 29, 2026 at 7:43 pm

    You can use prevAll [docs] and nextAll [docs]:

    $(this).prevAll().each(function(i) {
        $(this).text(i+1);
    });
    
    $(this).nextAll().each(function(i) {
        $(this).text(i+1);
    });
    

    DEMO

    Btw. you are not traversing up or down the tree, you are always staying at the same level.

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

Sidebar

Related Questions

I'm trying to build a plugin that contains some native libraries. The project has
I'm trying to build a simple jquery plugin that can take selectors as parameters.
I'm trying to build a jQuery plugin that allows you to drag and draw
I'm trying to build a jQuery plugin that filters the provided jQuery object to
I'm trying to build an image gallery (or, ideally, find a jquery plugin) that
I'm trying to build an autocomplete using jQuery plugin autocomplete from this site .
I'm trying to achieve this effect with jQuery. I wrote some of the code,
I am trying to build a Hudson plugin I've modified and it requires jdk1.6.
I'm trying to build some .ascx controls into a class library for plugins for
I'm trying to build an FAQ page. The page will have 2 columns: first

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.